Adobe AIR Application to play a sound file

Advertisement
Post Pic

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.

Related Entries...

You Might Like:

Advertisement

Please let us know your feedback about the article through the comments section below, we want to hear from you about our website. And your comment / advice may help us to serve you better in upcoming articles.

Thank You!
Vivekanand [Founder of DeveloperSnippets]

One Response

[...] Adobe AIR Application to play a sound file » This Summary is from an article posted at Developer Snippets on Friday, August 31, 2007 AIR [...]

Leave Your Response

* Name, Email, Comment are Required

Write For Us

Online Sponsors

Start Foreign Exchange Trading today with the Forex Affiliate Program and also you can have access Online Forex News to know what happens every single moment.


Forex Floor


Switch to our mobile site