AudioCuePoint class now baked into SoundManager!

Reynaldo February 15th, 2008

Hi All:

The AudioCuePoint class is now intergrated into the SoundManager class making it that much easier to use. Now you can directly add cue points to your mp3 files directly from the SoundManager instance! Here is a sample MP3 player with code:

Sample:

This movie requires Flash Player 9

Code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
import com.reyco1.audio.SoundManager;
import com.reyco1.events.SoundEvent;
import com.reyco1.util.DateUtil;
import flash.events.MouseEvent;
 
var sm:SoundManager = new SoundManager();
var myMP3:String = "Bachata";
 
sm.addToQueue(myMP3, "http://www.reynaldocolumna.com/blog/stuff/bachata.mp3");
 
sm.addEventListener(SoundEvent.LOAD_PROGRESS, loadProgressHanlder);
sm.addEventListener(SoundEvent.ALL_SOUNDS_LOADED, soundsLoadedHanlder);
sm.addEventListener(SoundEvent.SOUND_PROGRESS, positionHandler);
sm.addEventListener(SoundEvent.CUE_POINT, cuePointHandler);
 
sm.loadSounds();
 
this.playBtn.enabled = false;
this.stopBtn.enabled = false;
 
function loadProgressHanlder($event:SoundEvent):void
{
	statusTxt.htmlText = "Loading "+$event.params.currentFileIndex+" of "+$event.params.totalFiles+", "+$event.params.percent+"%"
}
 
function soundsLoadedHanlder($event:SoundEvent):void
{
	statusTxt.text = "Press play."; 
 
	sm.addCuePoint(myMP3, {name:"pnt1", time:5});
	sm.addCuePoint(myMP3, {name:"pnt2", time:10});
 
	pBar.mode = "manual";
	pBar.maximum = sm.getDuration(myMP3);
	pBar.minimum = 0;
 
	this.playBtn.enabled = true;
	this.stopBtn.enabled = true;
 
	this.stopBtn.addEventListener(MouseEvent.CLICK, stopSound);
	this.playBtn.addEventListener(MouseEvent.CLICK, playSound);
}
 
function playSound($event:MouseEvent):void
{
	if(sm.isPaused(myMP3)){
		sm.play(myMP3);
		sm.getChannel(myMP3).addEventListener(SoundEvent.SOUND_COMPLETE, stopSound);
		playBtn.label = "Pause";
	} else{
		sm.pause(myMP3);
		playBtn.label = "Play";
		statusTxt.text = "Paused at "+DateUtil.secToFormattedTime(sm.getPosition(myMP3))+".";
	}
}
 
function stopSound($event:*):void
{
	resetApp();
}
 
function resetApp():void
{
	sm.stop(myMP3);
	sm.getChannel(myMP3).removeEventListener(SoundEvent.SOUND_COMPLETE, stopSound);
        sm.resetCuePoints(myMP3);
	statusTxt.text = "Press play.";
	playBtn.label = "Play";
	pBar.value = 0;
}
 
function positionHandler($event:SoundEvent):void
{
	pBar.value = $event.params.position
	statusTxt.htmlText = "<strong>"+$event.params.name+"</strong> playing at "+DateUtil.secToFormattedTime($event.params.position)+" of "+DateUtil.secToFormattedTime($event.params.duration)+" seconds. Percentage : "+$event.params.percentage+"%";
}
 
function cuePointHandler($event:SoundEvent):void
{
	cueTxt.text = "cueOwner: "+$event.params.owner+", cueName: "+$event.params.name+", cueTime: "+$event.params.time;
}

You can get the code from the Reyco1 AS3 Tools samples folder.

Trackback URI | Comments RSS

Leave a Reply

  • Friends

  • Props

  • Donations

  • website counter
  • Archives

  • Feedburner