0 Replies Latest reply on Jun 29, 2007 7:27 AM by Handycam

    Audio player problem

    Handycam Level 1
      I'm trying to use some audio player code, this time taken from the O'Reilly flex book. The problem is, when I run the application the browser crashes. No errors show up in the debugger. It only happens on the Mac, windows vista works ok in FF2 and IE7. Thoughts?

      The code has 2 parts, the application file and the AS class file.

      Here's the application:

      <?xml version="1.0" encoding="utf-8"?>
      <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml">
      import com.oreilly.programmingflex.SoundPlayer;
      //Initialize the soundPlayer as soon as the application start
      public var soundPlayer:SoundPlayer = new SoundPlayer("assets/sound.MP3");
      <mx:Text text="{soundPlayer.songName}" id="songName" width="100%"/>
      <mx:HBox width="100%">
      <mx:Button label="Play" click="soundPlayer.play( )"/>
      <mx:Button label="Stop" click="soundPlayer.stop( )"/>
      <mx:Button label="Pause" click="soundPlayer.pause( )"/>

      And here's the class:

      package com.oreilly.programmingflex
      import flash.media.SoundChannel;
      import flash.media.Sound;
      import flash.net.URLStream;
      import flash.events.Event;
      import flash.media.ID3Info;
      import flash.net.URLRequest;
      import flash.events.EventDispatcher;

      public class SoundPlayer extends EventDispatcher
      public var songName:String = "Loading";

      private var _sound:Sound;
      private var _soundChannel:SoundChannel;
      private var _currentPosition:Number;

      public function SoundPlayer(url:String)
      _sound = new Sound(new URLRequest(url));
      //Subscribe to the ID3 event so we can retrieve the songName
      play( );

      public function stop( ):void
      _soundChannel.stop( );
      //reset the position so play( ) start from the begining
      _currentPosition = 0;

      public function pause( ):void
      //store the position so we can resume playback
      _currentPosition = _soundChannel.position;
      _soundChannel.stop( );

      public function play( ):void
      //If it is already playing, stop playback
      if(_soundChannel != null)
      _soundChannel.stop( );
      //Store a reference to the playing channel
      _soundChannel = _sound.play(_currentPosition);
      //Set the volume, valid values are from 0 to 1
      _soundChannel.soundTransform.volume = .7;

      private function id3Handler(id3Event:Event):void
      songName = _sound.id3.songName;
      dispatchEvent(new Event("songNameChanged"));