
Welcome Guest
|
#1
|
|||
|
|||
|
sound and loader problem
hi everybody
i am working on swf and mp3 player, i embed it in html and i am passing url of sound from javascript to player, i am controlling play stop of sound from html-javascript. there are three buttons two plays swf audio while one is for mp3 sound. all are playing sounds. but the problem is i want to play one sound at a time. when i click one button the sound play and if i click it again the sound should stop or if i click any other button the first sound should stop and next sound should play.. but all play at a time.. when i click one button first time i pass url of sound from js to flash and i pass null on clicking it again.. while on press next button i pass other url so how can i stop or discard the previous playing stream and intiate a fresh sound stream.. i try soundchannel.stop and sound.close but i doesnt work for me any suggestion is this regard willbe highly appreciated. here is my code: Code:
import flash.events.IOErrorEvent;
import flash.events.ProgressEvent;
import flash.external.ExternalInterface;
import flash.events.Event;
import flash.media.Sound;
import flash.media.SoundChannel;
import flash.net.URLRequest;
import flash.display.Loader;
import flash.display.MovieClip;
import flash.display.LoaderInfo;
var song:SoundChannel = new SoundChannel();
var swf:Loader = new Loader();
var sound_loc:String;
var soundFactory:Sound = new Sound();
var request:URLRequest;
ExternalInterface.addCallback("sendTextToFlash", getTextFromJavaScript);
function getTextFromJavaScript(str:String):void {
sound_loc = str;
request = new URLRequest(sound_loc);
if(sound_loc == '' || sound_loc == null || sound_loc == 'null') {
song.stop();
soundFactory.close();
request = new URLRequest(null);
}
}
try {
if(contains(swf)) {
removeChild(swf);
}
swf = new Loader();
swf.load(request);
addChild(swf);
} catch(e:Error) {
trace(e);
} finally {
soundFactory.close();
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);
song = soundFactory.play();
}
function completeHandler(event:Event):void {
trace("completeHandler: " + event);
}
function id3Handler(event:Event):void {
trace("id3Handler: " + event);
}
function ioErrorHandler(event:Event):void {
trace("ioErrorHandler: " + event);
}
function progressHandler(event:ProgressEvent):void {
trace("progressHandler: " + event);
} |
«
Previous Thread
|
Next Thread
»
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| preloader doesn't work with sound | jason456 | Sound and Music |
2 | 09-02-2006 12:14 PM |
| Preloading Sound Across Multiple SWFs | bidayuhboy | Newbies |
4 | 06-06-2005 07:24 PM |
| Playback hangs until clip fully loaded. | medvet | Flash MX |
1 | 07-17-2003 08:56 PM |





