I'm currently trying to build a very basic MP3 audio player with Flex2,
based on the SoundChannel code example.
The MP3 file is successfully loaded, ID3 tags are available, length is > 0.
But when I press play I've got immediatly the soundComplete event.
What's wrong here?

I've tried with several MP3, same problem...

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.macromedia.com/2005/mxml";
        creationComplete="onCreationComplete()">
        
        <mx:Script>
                <![CDATA[
                        import flash.util.trace;
                    import flash.util.Timer;
                     import flash.net.URLRequest;
                    import flash.media.Sound;
                    import flash.media.SoundChannel;
                    import flash.events.*;
                    
                    private var soundUrl:String =
"http://localhost/test.mp3";;
                private var soundFactory:Sound;
                private var channel:SoundChannel;
                private var positionTimer:Timer;
                
                private function onCreationComplete():void {
                        var request:URLRequest = new URLRequest(soundUrl);
                    soundFactory = new Sound();
                    soundFactory.addEventListener(Event.COMPLETE,
completeHandler);
                    soundFactory.addEventListener(Event.ID3, id3Handler);
                    soundFactory.addEventListener(IOErrorEvent.IO_ERROR,
ioErrorHandler);
                    soundFactory.addEventListener(ProgressEvent.PROGRESS,
progressHandler);
                    soundFactory.load(request);
                }
                
                private function positionTimerHandler(event:TimerEvent):void
{
                    //trace("positionTimerHandler: " + channel.position);
                }
        
                private function completeHandler(event:Event):void {
                    trace("completeHandler: " + event);
                    playButton.enabled = true;
                }
        
                private function id3Handler(event:Event):void {
                    trace("id3Handler: " + event);
                }
        
                private function ioErrorHandler(event:Event):void {
                    trace("ioErrorHandler: " + event);
                }
        
                private function progressHandler(event:ProgressEvent):void {
                    trace("progressHandler: " + event);
                }
        
                private function soundCompleteHandler(event:Event):void {
                    trace("soundCompleteHandler: " + event);
                        positionTimer.stop();
                }
                
                private function onPlayClick():void {
                        channel = soundFactory.play();
                    channel.addEventListener(Event.SOUND_COMPLETE,
soundCompleteHandler);
        
                    positionTimer = new Timer(50);
                    positionTimer.addEventListener(TimerEvent.TIMER,
positionTimerHandler);
                        positionTimer.start();
                }
                ]]>
        </mx:Script>
        
        <mx:Button id="playButton"
                click="onPlayClick()"
                enabled="false"
                label="Play" />
        
</mx:Application>

Benoit Hediard




--
Flexcoders Mailing List
FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.com 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/flexcoders/

<*> To unsubscribe from this group, send an email to:
    [EMAIL PROTECTED]

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/
 


Reply via email to