23 Replies Latest reply: Sep 13, 2011 9:16 PM by M.S.H RSS

    AIR - Android -- A piece of ****

    M.S.H Community Member

      Hi,

       

      I spent my precious 2 days time to write an application (AIR-Android) which can play internet radio stations (streamed audio). Every thing worked great when I used 'Test Movie' or Ctrl+ENTER. But same is not working when I generated the .apk and installed on HTC Desire HD (running Android 2.2 and have AIR with latest updates).

       

      I have predefined few internet radio stations and clicking on the station name should start playing the radio. I have used the SoundChannel with 3 second buffering option. On the device application triggers the buffering event but never comes out of that or plays the audio.

       

      I have tried few things:

      1. Prepared a test file with only one station

      2. In publish settings --> Audio Stream set the bit rate to 24kbps which is same as that station is streamed

      3. Increased the script limit to 30 seconds

      4. Tried to use Security.allowDomain() which caused runtime error (3207 Application-sandbox content cannot access this feature)

       

      I used the station "http://stream.radiosai.net:8004" for testing. The station is active, streaming in MP3 format and able to listen through the Windows Media Player / VLC.

      I prepared a self signed AIR for desktop as well and installed on my laptop (Windows 7 64-bit) but same problem.

       

      I have prepared this using Air for Android extn for Flash CS5.

       

      Please let me know if anybody has faced the same problem, suggest me if I am really missing anything.

       

      Here the AS3 code used for testing.

      ===========================

       

       

      import flash.media.Sound;

      import flash.media.SoundChannel;

      import flash.media.SoundLoaderContext;

       

      import flash.net.URLRequest;

      import flash.events.IOErrorEvent;

       

      import flash.utils.Timer;

      import flash.events.TimerEvent;

       

       

      const AFRICA_STREAM:String = "http://stream.radiosai.net:8004";

       

       

      var isPlaying:Boolean = false;

      var recentlyPlayed:String = "";

       

       

       

      var streamSound:Sound;

      var streamChannel:SoundChannel;

      var streamContext:SoundLoaderContext = new SoundLoaderContext(3000,false);

       

      var streamTimer:Timer;

       

      africa_mc.addEventListener(MouseEvent.CLICK, handleStationSelect);

       

       

      function handleStationSelect(evt:MouseEvent):void {

           if (isPlaying == true) {

                streamChannel.stop();

                streamSound = null;

                streamChannel = null;

                isPlaying = false;

                streamTimer.stop();

                removeListeners();

           }

           switch (evt.target.name) {

                case "africa_mc" :

                     if (recentlyPlayed != "africa_mc") {

                          playStation(AFRICA_STREAM);

                          recentlyPlayed = "africa_mc";

                     }

                     break;

           }

      }

       

       

       

      function playStation(streamUrl:String):void {

           streamSound = new Sound();

           addListeners();

           streamSound.load(new URLRequest(streamUrl), streamContext);

           streamChannel = streamSound.play();

           isPlaying = true;

       

           streamTimer = new Timer(2000);

           streamTimer.addEventListener(TimerEvent.TIMER, checkPlayState);

           streamTimer.start();

      }

       

       

       

      function soundIoError(evt:IOErrorEvent):void {

           streamChannel.stop();

           streamSound.close();

           streamSound = null;

           streamChannel = null;

           removeListeners();

           play_state.text = "IO Error";

      }

       

      function checkPlayState(evt:TimerEvent):void {

           if (streamSound.isBuffering == true) {

                play_state.text = "Buffering...";

           }

           else {

                play_state.text = "Playing...";

           }

      }

       

      function addListeners() {

           streamSound.addEventListener(IOErrorEvent.IO_ERROR, soundIoError);

      }

       

      function removeListeners() {

           streamSound.removeEventListener(IOErrorEvent.IO_ERROR, soundIoError);

           streamTimer.removeEventListener(TimerEvent.TIMER, checkPlayState);

      }

       

       

      =========================================================

       

      Its very sad that adobe has created something fully buggy and works only on IDE but not on actual device. More sad part is adobe is not even cared to have a look into the issue.