LOADING
Loading
Hi , welcome back.
LogoutLOGOUT
 
  Lost password?  
Hi
 




 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 12-11-2008, 07:46 AM
maani786 maani786 is offline
Registered User
 
Join Date: Dec 2008
Posts: 3
Rep Power: 0
maani786 is on a distinguished road
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);
        
    }
Reply With Quote
 


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

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




All times are GMT. The time now is 11:17 PM.