Avatar billede bogologo Nybegynder
25. januar 2008 - 16:43 Der er 1 løsning

Flash AS3 Event.SOUND_COMPLETE

Har lavet en simpel audio player i flash.
(kildekode i bunden)

mit problem er at min Event.SOUND_COMPLETE aldrig bliver "fanget"

nogen forslag til hvad jeg har gjort forkert?
*************
Kildekode:
import flash.events.Event;
import flash.events.ProgressEvent;
import flash.media.Sound;
import flash.net.URLRequest;
import flash.media.ID3Info;

var s:Sound = new Sound();
s.addEventListener(ProgressEvent.PROGRESS, onLoadProgress);
s.addEventListener(Event.COMPLETE, onLoadComplete);
s.addEventListener(IOErrorEvent.IO_ERROR, onIOError);

var id:int = 1;
var req:URLRequest = new URLRequest(id+".mp3");
s.load(req);
var channel:SoundChannel;
var localSound:Sound;
function onLoadProgress(event:ProgressEvent):void
{
    var loadedPct:uint =        Math.round(100 * (event.bytesLoaded / event.bytesTotal));
    trace ("The sound is " + loadedPct + "% loaded.");
    songText.text = loadedPct + "% loaded.";
}

function onLoadComplete(event:Event):void
{
  localSound = event.target as Sound;
  channel = localSound.play();
  channel.stop();
 
  songText.text  = s.id3.songName + " - " + s.id3.artist;
}
function onIOError(event:IOErrorEvent)
{
    songText.text = "The sound could not be loaded";
    trace("The sound could not be loaded: " + event.text);
}

//----- virker ikke!!!!!--------------

s.addEventListener(Event.SOUND_COMPLETE, onPlaybackComplete);
function onPlaybackComplete(event:Event)
{
    songText.text = "The sound has finished";
    trace("The sound has finished playing.");

}

//-----------------------------------------

//****************BUTTONS***********************************************
var pausePosition:int = 0;
btnPlay.addEventListener(MouseEvent.CLICK,btnPlayClickHandler);
function btnPlayClickHandler(Event:MouseEvent):void{
    channel = localSound.play(pausePosition);
    btnPlay.visible = false;
}

btnPause.addEventListener(MouseEvent.CLICK,btnPauseClickHandler);
function btnPauseClickHandler(Event:MouseEvent):void{
    pausePosition = channel.position;
    channel.stop();
    btnPlay.visible = true;
}

btnNext.addEventListener(MouseEvent.CLICK, nextSong);
function nextSong(event:MouseEvent):void {
    pausePosition = 0;
    if (id == 4)
    {
        id = 0
    }
    id++;
    channel.stop();
    trace(id);
    songLoader(id);
    //s.load(req);
    btnPlay.visible = true;
}

//**************SONG LOADER***************************************
function songLoader(id)
{
    var s:Sound = new Sound();
    s.addEventListener(ProgressEvent.PROGRESS, onLoadProgress);
    s.addEventListener(Event.COMPLETE, onLoadComplete);
    s.addEventListener(IOErrorEvent.IO_ERROR, onIOError);
   
    var req:URLRequest = new URLRequest(id+".mp3");
    s.load(req);
    function onLoadProgress(event:ProgressEvent):void
    {
        var loadedPct:uint =        Math.round(100 * (event.bytesLoaded / event.bytesTotal));
        trace ("The sound is " + loadedPct + "% loaded.");
        songText.text = loadedPct + "% loaded.";
    }
   
    function onLoadComplete(event:Event):void
    {
      localSound = event.target as Sound;
      //channel = localSound.play(180000);
      songText.text  = s.id3.songName + " - " + s.id3.artist;
    //localSound.play(40000);
    }
    function onIOError(event:IOErrorEvent)
    {
        songText.text = "The sound could not be loaded";
        trace("The sound could not be loaded: " + event.text);
    }
}
Avatar billede bogologo Nybegynder
25. januar 2008 - 19:44 #1
lukket
Avatar billede Ny bruger Nybegynder

Din løsning...

Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.

Loading billede Opret Preview
Kategori
Kurser inden for grundlæggende programmering

Log ind eller opret profil

Hov!

For at kunne deltage på Computerworld Eksperten skal du være logget ind.

Det er heldigvis nemt at oprette en bruger: Det tager to minutter og du kan vælge at bruge enten e-mail, Facebook eller Google som login.

Du kan også logge ind via nedenstående tjenester