Adobe AIR Application to play a sound file
Categories: Featured, Programming
Tags: Adobe Air
Written By: admin
AIR is rocking in the web world, if you guys! Search for Adobe AIR you will get tons of web snippets and sample applications which are developed using this awesome enough technology.
As Adobe experts says Adobe AIR, formerly code-named Apollo, is a cross-operating system runtime that allows developers to use their existing web development skills to build and deploy rich Internet applications to the desktop. Using AIR we can develop desktop applications using HTML, JavaScript, XML, AJAX, Flash, Flex etc.,
In this tutorial, you guys! Can learn how we can play an audio file, the audio file might be of .mp3 / .wmv or any other compatible audio files.
The application has got one button, on clicking of the button the particular audio file will be played, I have taken .mp3 file as an example. Below is the code for the index.html file, this file has got simple JavaScript code only few lines of code are required.
Copy the below code and paste it in between tags:
<script>
function init()
{
document.getElementById("playButt").addEventListener("click", playFile);
}
function playFile()
{
var audiofile = air.File.applicationResourceDirectory.resolve("rockup.mp3");
var mp3File = new air.Sound(new air.URLRequest(audiofile.nativePath));
mp3File.play();
}
</script>
Call the init() function on page load, so onload of the page call the init() function like –
<body onLoad="init()">
So its done, just we need to place a button, create a button like –
<input id="playButt" type="button" value="Play >" />
So we have done with the code, below is the full snippet code to copy:
<html>
<head>
<title>Playing a Sound</title>
<script>
function init ()
{
document.getElementById( "playButt" ).addEventListener( "click", playFile );
}
function playFile()
{
var audiofile = air.File.applicationResourceDirectory.resolve( "rockup.mp3" );
var mp3File = new air.Sound( new air.URLRequest( audiofile.nativePath ) );
mp3File.play();
}
</script>
</head>
<body onLoad="init()">
<input id="playButt" type="button" value="Play >" />
</body>
</html>
So Guys! What are you waiting for ROCK UP THE WEB WORLD WITH ADOBE AIR.

(2 votes, average: 4 out of 5)








August 31st, 2007 at 1:54 pm
[…] Adobe AIR Application to play a sound file » This Summary is from an article posted at Developer Snippets on Friday, August 31, 2007 AIR […]