Jump to content
GreenSock

Search In
  • More options...
Find results that contain...
Find results in...
lazarsto

play mp3 files simultaneously

Recommended Posts

Hi,

Is ti possible to play mp3 files simultaneously.

For example I have drums.mp3 , guitar.mp3, bass.mp3 and I want to play them in the same time, simultaneously.

 

var queue:LoaderMax = new LoaderMax({name:"mainQueue",onProgress:progressHandler,onComplete:completeHandler,onError:errorHandler});

var sound1:MP3Loader = new MP3Loader("mp3/guitar_1.mp3",{name:"guitar_1", autoPlay:false});
var sound2:MP3Loader = new MP3Loader("mp3/drums.mp3",{name:"drums",autoPlay:false});

queue.append(sound1);
queue.append(sound2);
queue.load();

 

But it doesn't start simultaneously, sound2 late.

Something like "TweenAlign.START"

Thanks

Link to comment
Share on other sites

I don't see your code for where you play the audio. It looks like this code simply loads it.

Link to comment
Share on other sites

Oh sorry instead autoPlay:false it's autoPlay:true,

Anyway could you give me some hint or code how to play mp3 files simultaneously.

Thanks a lot

Similar as

myTimeline.insertMultiple([new TweenLite(mc, 1, {y:"100"}), new TweenLite(mc2, 1, {x:20}), new TweenLite(mc3, 1, {alpha:0.5})], 0, TweenAlign.START);

but for sounds

Link to comment
Share on other sites

I did something like this for start and now it works fine, all the sounds start simultaneously when I listen them.

 

var queue:LoaderMax = new LoaderMax({name:"mainQueue",onComplete:completeHandler});

var sound1:MP3Loader = new MP3Loader("mp3/guitar_1.mp3",{name:"guitar_1", autoPlay:false});
var sound2:MP3Loader = new MP3Loader("mp3/drums.mp3",{name:"drums",autoPlay:false});
var sound3:MP3Loader = new MP3Loader("mp3/vokal_1.mp3",{name:"drums",autoPlay:false});
var sound4:MP3Loader = new MP3Loader("mp3/bass_1.mp3",{name:"drums",autoPlay:false});

sound1.load();
sound2.load();
sound3.load();
sound4.load();

queue.load();

function toggleSound(event:MouseEvent):void
{
sound4.playSound();
sound3.playSound();
sound2.playSound();
sound1.playSound();
}

function completeHandler(event:LoaderEvent):void
{
button.addEventListener(MouseEvent.CLICK, toggleSound);
}

Link to comment
Share on other sites

Nope , i was wrong, sounds still does not start simultaneously :(

Link to comment
Share on other sites

You forgot to put the MP3Loaders into the queue. Your code would have the completeHandler called immediately because the queue is empty. Make sure all the sounds are adequately loaded before you playSound().

Link to comment
Share on other sites

Hi, I loaded all the sounds now before i play them, but still has delay depending on sound order

package 
{
import com.greensock.*;
import com.greensock.easing.*;
import com.greensock.events.LoaderEvent;
import com.greensock.loading.*;
import com.greensock.loading.display.*;
import com.greensock.plugins.*;

import flash.display.*;
import flash.events.*;
import flash.text.*;

public class Mp3 extends MovieClip
{
	public var load_btn:MovieClip;
	private var _xmlLoader:XMLLoader;
	private var _musicLoader:LoaderMax;
	private var _xmlProgress:ProgressCircleMax;
	private var _musicProgress:ProgressCircleLite;

	public function Mp3():void
	{
		_init();
	}

	private function _init():void
	{
		LoaderMax.activate([MP3Loader]);
		TweenPlugin.activate([ColorTransformPlugin]);
		_xmlLoader = new XMLLoader("xml/musicLoader.xml",{name:"music",estimatedBytes:276700,onComplete:_xmlCompleteHandler,onError:_errorHandler});
		_xmlProgress = new ProgressCircleMax({bgColor:0x0000FF,trackColor:0xFF0000,trackAlpha:0.2});
		this.addChild(_xmlProgress);
		_xmlProgress.addLoader(_xmlLoader);
		_xmlLoader.load();
		_musicProgress = new ProgressCircleLite({radius:26,thickness:4,trackColor:0xFFFFFF,trackAlpha:0.25,trackThickness:4,autoTransition:false});
		this.addChild(_musicProgress);
		_musicProgress.mouseEnabled = false;
		_musicProgress.x = 69;
		_musicProgress.y = 389;

		this.load_btn.addEventListener(MouseEvent.CLICK, _loadHandler);
	}

	//---- EVENT HANDLERS ----------------------------------------------------------------

	private function _xmlCompleteHandler(event:Event):void
	{

		//retreive the "imagesLoader" LoaderMax instance that was dynamically created by parsing the XML file.
		_musicLoader = LoaderMax.getLoader("musicLoader") as LoaderMax;
		_musicProgress.addLoader(_musicLoader);
		_musicLoader.addEventListener(LoaderEvent.PROGRESS, _progressHandler);
		_musicLoader.addEventListener(LoaderEvent.COMPLETE, _completeHandler);
	}
	private function _completeHandler(event:LoaderEvent):void
	{
		LoaderMax.getLoader("vokal_1").playSound();
		LoaderMax.getLoader("drums").playSound();
		LoaderMax.getLoader("bass_1").playSound();
		LoaderMax.getLoader("acoustic_1").playSound();
		LoaderMax.getLoader("guitar_1").playSound();
	}
	private function _progressHandler(event:LoaderEvent):void
	{
		trace(int(event.target.progress * 100));
	}
	private function _errorHandler(event:LoaderEvent):void
	{
		trace("error occured with " + event.target + ": " + event.text);
	}
	private function _loadHandler(event:Event):void
	{
		_musicLoader.load();
	}

}

}

 

And xml is








Could you help me how to play all the sounds simultaneously.

Thanks a lot

Link to comment
Share on other sites

If the sounds aren't playing simultaneously, then either you have some padding at the beginning of some of the MP3 files that make them SOUND like they're not aligned or it's simply a Flash Player issue (maybe you're on a slower system that can't handle the CPU load required by decoding and playing all of those audio streams at the same time). Tough to say without seeing the files and compiling for myself.

Link to comment
Share on other sites

Like I said, it sounds like a Flash Player / CPU issue with playing/decoding that many MP3s together simultaneously. Maybe try delaying the playSound() calls at least 0.5 seconds AFTER all the files fully load into Flash so that it gives Flash a brief moment to deal with the files that it just loaded.

Link to comment
Share on other sites

Hm, thanks for explanation.

Could you please write a code for delaying?

Or should I try to make mp3 files lower quality?

Thanks

Link to comment
Share on other sites

Does anybody knows how to solve problem above, or for now it just impossible in flash player 10?

Thank you

Link to comment
Share on other sites

Aside from trying that delay suggestion I offered, no, I don't have any other ideas. It may just be impossible.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×