Learn Photoshop, Flash, Adobe AIR, ExtJS, jQuery, Ajax, Dojo, HTML, CSS, JavaScript, XML, Accessibility, Database, DWR, Gears, GWT, Java, JSON, MooTools, Office, Perl, PHP, Programming, Prototype, Scriptaculous and more

Want to explore your choice of video from all over world at once place! then what are you waiting for, just click, explore and learn.

Tech Video Bytes

Adobe AIR Application to play a sound file

Categories: Featured, Programming
Tags:
Written By: admin
1 Star2 Stars3 Stars4 Stars5 Stars (2 votes, average: 4 out of 5)
Loading ... Loading ...

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.

One Response to “Adobe AIR Application to play a sound file”

  1. University Update - AJAX - Adobe AIR Application to play a sound file Says:

    […] 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 a Reply

Featured & Popular Articles