Bonjour,

Voilà, j'ai un player Mp3 avec playliste XML. Jusqu'ici tout va bien.

Il y a un fichier *.SWF, un *.FLA, un *.AS et un *.FLP.

Dans le FLA il n'y a aucun code AS3, tout le code est dans le fichier AS qui est un package et le fichier FLP qui comporte toutes les function des boutons...

Voici le code du fichier AS :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
package {
 
	import flash.events.*;
	import fl.events.ListEvent;
	import flash.media.Sound;
	import flash.media.SoundChannel;
	import flash.media.SoundTransform;
	import flash.display.MovieClip;
	import flash.net.URLLoader;
	import flash.net.URLRequest;
 
	public class Mp3Main extends MovieClip{
		public var url:URLRequest;
		public var xmlLoad:URLLoader;
		public var musicXML:XML;
		public var song:Sound;
		public var channel:SoundChannel;
		public var sndTrans:SoundTransform;
		public var position:Number;
 
		/*The constructor mainly sets up the event listeners, but it also
		starts loading the XML playlist file.*/
		public function Mp3Main() {
			position = 0;
			sndTrans = new SoundTransform(vol_mc.percent);
			url = new URLRequest("playlist_1_1.xml");
			xmlLoad = new URLLoader(url);
			xmlLoad.addEventListener(Event.COMPLETE, xmlComplete);
 
			playList.addEventListener(ListEvent.ITEM_CLICK, SnglClick, false, 0, true);
			vol_mc.addEventListener("volume_change", updateVolume, false, 0, true);
			seek_mc.addEventListener("seek_change", changeSeekBar, false, 0, true);
 
 
 
		/*****************Button Event Listeners************************/
 
			playPause_mc.addEventListener(MouseEvent.MOUSE_OVER, PlayOver);
			playPause_mc.addEventListener(MouseEvent.MOUSE_OUT, PlayOut);
			playPause_mc.addEventListener(MouseEvent.MOUSE_DOWN, PlayDown);
			playPause_mc.addEventListener(MouseEvent.MOUSE_UP, PlayUp);
 
			stop_mc.addEventListener(MouseEvent.MOUSE_OVER, StopOver);
			stop_mc.addEventListener(MouseEvent.MOUSE_OUT, StopOut);
			stop_mc.addEventListener(MouseEvent.MOUSE_DOWN, StopDown);
			stop_mc.addEventListener(MouseEvent.MOUSE_UP, StopUp);
 
			mute_mc.addEventListener(MouseEvent.MOUSE_OVER, MuteOver);
			mute_mc.addEventListener(MouseEvent.MOUSE_OUT, MuteOut);
			mute_mc.addEventListener(MouseEvent.MOUSE_DOWN, MuteDown);
			mute_mc.addEventListener(MouseEvent.MOUSE_UP, MuteUp);
 
			back_mc.addEventListener(MouseEvent.MOUSE_OVER, BackOver);
			back_mc.addEventListener(MouseEvent.MOUSE_OUT, BackOut);
			back_mc.addEventListener(MouseEvent.MOUSE_DOWN, BackDown);
			back_mc.addEventListener(MouseEvent.MOUSE_UP, BackUp);
 
			forward_mc.addEventListener(MouseEvent.MOUSE_OVER, ForwardOver);
			forward_mc.addEventListener(MouseEvent.MOUSE_OUT, ForwardOut);
			forward_mc.addEventListener(MouseEvent.MOUSE_DOWN, ForwardDown);
			forward_mc.addEventListener(MouseEvent.MOUSE_UP, ForwardUp);
		}
 
		/*This function is used to display the minutes and seconds of the current song.
		It is only used in the updateSeek() function.*/
		public function formatTime(time:Number):String {
			var min:String = Math.floor(time/60000).toString();
			var sec:String = (Math.floor((time/1000)%60) < 10)? "0" + Math.floor((time/1000)%60).toString() : Math.floor((time/1000)%60).toString();
			return(min+":"+sec);
		}
 
	/***********************Event Handlers****************************/
		/*I want to start loading the first song right after filling the
		List component.  If you want it to play automaticly, here is where
		you do that.*/
		private function xmlComplete(event:Event):void {
			var item:Object;
			musicXML = new XML(event.currentTarget.data);
 
			for each(var prop:XML in musicXML.song){
				item = new Object();
				item.label = prop.@disp;
				item.data = prop.@id;
				playList.addItem(item);
 
			}
			song = new Sound();
			song.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler, false, 0, true);
			song.load(new URLRequest(playList.getItemAt(0).data));
			this.addEventListener(Event.ENTER_FRAME, updateSeek, false, 0, true);
			playList.selectedIndex = 0;
		}
 
		/*When you choose a new item on the List it will play for you.*/
		private function SnglClick(event:ListEvent):void {
			var item:Object = event.item;
 
			try 
			{song.close();} 
			catch(error) 
			{}
			try 
			{channel.stop();} 
			catch(error) 
			{}
 
			song = new Sound();
			song.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler, false, 0, true);
			song.load(new URLRequest(item.data));
			channel = song.play();
			channel.soundTransform = (mute_mc.isMute)? new SoundTransform(0) : sndTrans;
			channel.addEventListener(Event.SOUND_COMPLETE, soundComplete, false, 0, true);
			position = 0;
			playPause_mc.playing = true;
			playPause_mc.gotoAndStop('pause');
		}
 
		/*When a song ends, this will take you to the next song.*/
		private function soundComplete(event:Event):void {
			if(playList.length > playList.selectedIndex + 1){
				playList.selectedIndex++;
				playList.scrollToSelected();
			} else {
				playList.selectedIndex = 0;
				playList.scrollToSelected();
			}
			playList.dispatchEvent(new ListEvent(ListEvent.ITEM_CLICK, false, true, 0, playList.selectedIndex, playList.selectedIndex, playList.selectedItem));
		}
 
		/*The next two are called handling custom events from within SeekControl.as
		and VolControl.as*/
		private function updateVolume(event:Event):void {
			sndTrans.volume = vol_mc.percent;
			channel.soundTransform = (mute_mc.isMute)? new SoundTransform(0) : sndTrans;
		}
		private function changeSeekBar(event:Event):void {
			position = (song.length/(song.bytesLoaded/song.bytesTotal)) * seek_mc.percent;
			if(playPause_mc.playing){
				channel.stop();
				channel = song.play(position);
				channel.soundTransform = (mute_mc.isMute)? new SoundTransform(0) : sndTrans;
				channel.addEventListener(Event.SOUND_COMPLETE, soundComplete, false, 0, true);
			}
		}
		private function updateSeek(event:Event):void {
			if(channel != null && playPause_mc.playing) {
				var perc:Number = channel.position / (song.length/(song.bytesLoaded/song.bytesTotal));
				seek_mc.moveSeekPos(perc);
				display_mc.timeDisp.text = formatTime(channel.position) + "/" + formatTime((song.length/(song.bytesLoaded/song.bytesTotal)));
			}else {
				display_mc.timeDisp.text = formatTime(position) + "/" + formatTime((song.length/(song.bytesLoaded/song.bytesTotal)));
			}
		}
 
		private function ioErrorHandler(event:Event):void {
			trace("ioErrorHandler: " + event);
		}
 
	/*******************PlayPause Handlers*************************/
		private function PlayOver(event:MouseEvent):void {
			var obj:Object = event.currentTarget;
			if(obj.playing) {
				obj.gotoAndStop('pause_over');
			} else {
				obj.gotoAndStop('play_over');
			}
		}
		private function PlayOut(event:MouseEvent):void {
			var obj:Object = event.currentTarget;
			if(obj.playing) {
				obj.gotoAndStop('pause');
			} else {
				obj.gotoAndStop('play');
			}
		}
		private function PlayDown(event:MouseEvent):void {
			var obj:Object = event.currentTarget;
			if(obj.playing) {
				obj.gotoAndStop('pause_down');
			} else {
				obj.gotoAndStop('play_down');
			}
		}
		/*Needs to switch between a pause and play button.*/
		private function PlayUp(event:MouseEvent):void {
			var obj:Object = event.currentTarget;
			if(obj.playing) {
				obj.gotoAndStop('play_over');
				position = channel.position;
				channel.stop();
				obj.playing = false;
			} else {
				obj.gotoAndStop('pause_over');
				channel = song.play(position);
				channel.soundTransform = (mute_mc.isMute)? new SoundTransform(0) : sndTrans;
				channel.addEventListener(Event.SOUND_COMPLETE, soundComplete, false, 0, true);
				obj.playing = true;
			}
		}
 
	/********************Stop Handlers************************/
		private function StopOver(event:MouseEvent):void {
			var obj:Object = event.currentTarget;
			obj.gotoAndStop('stop_over');
		}
		private function StopOut(event:MouseEvent):void {
			var obj:Object = event.currentTarget;
			obj.gotoAndStop('stop');
		}
		private function StopDown(event:MouseEvent):void {
			var obj:Object = event.currentTarget;
			obj.gotoAndStop('stop_down');
		}
		/*Needs to change the Play button as well.*/
		private function StopUp(event:MouseEvent):void {
			var obj:Object = event.currentTarget;
			channel.stop();
			position = 0;
			playPause_mc.playing = false;
			playPause_mc.gotoAndStop('play');
			obj.gotoAndStop('stop_over');
		}
 
	/********************Mute Handlers************************/
		private function MuteOver(event:MouseEvent):void {
			var obj:Object = event.currentTarget;
			if(obj.isMute) {
				obj.gotoAndStop('unmute_over');
			} else {
				obj.gotoAndStop('mute_over');
			}
		}
		private function MuteOut(event:MouseEvent):void {
			var obj:Object = event.currentTarget;
			if(obj.isMute) {
				obj.gotoAndStop('unmute');
			} else {
				obj.gotoAndStop('mute');
			}
		}
		private function MuteDown(event:MouseEvent):void {
			var obj:Object = event.currentTarget;
			if(obj.isMute) {
				obj.gotoAndStop('unmute_down');
			} else {
				obj.gotoAndStop('mute_down');
			}
		}
		private function MuteUp(event:MouseEvent):void {
			var obj:Object = event.currentTarget;
			if(obj.isMute) {
				obj.gotoAndStop('mute_over');
				obj.isMute = false;
				channel.soundTransform = sndTrans;
			} else {
				obj.gotoAndStop('unmute_over');
				obj.isMute = true;
				channel.soundTransform = new SoundTransform(0);
			}
		}
 
	/********************Back Handlers************************/
		private function BackOver(event:MouseEvent):void {
			var obj:Object = event.currentTarget;
			obj.gotoAndStop('back_over');
		}
		private function BackOut(event:MouseEvent):void {
			var obj:Object = event.currentTarget;
			obj.gotoAndStop('back');
		}
		private function BackDown(event:MouseEvent):void {
			var obj:Object = event.currentTarget;
			obj.gotoAndStop('back_down');
		}
		/*changes the List selection and then dispatches a fake ITEM_CLICK event.*/
		private function BackUp(event:MouseEvent):void {
			var obj:Object = event.currentTarget;
			obj.gotoAndStop('back_over');
 
			if(channel.position < 1500){
				if(playList.selectedIndex == 0){
					playList.selectedIndex = playList.length -1;
					playList.scrollToSelected();
				} else {
					playList.selectedIndex--;
					playList.scrollToSelected();
				}
				playList.dispatchEvent(new ListEvent(ListEvent.ITEM_CLICK, false, true, 0, playList.selectedIndex, playList.selectedIndex, playList.selectedItem));
			}else {
				try 
				{channel.stop();} 
				catch(error) 
				{}
				position = 0;
				if(playPause_mc.playing) {
					channel = song.play(0);
					channel.soundTransform = (mute_mc.isMute)? new SoundTransform(0) : sndTrans;
					channel.addEventListener(Event.SOUND_COMPLETE, soundComplete, false, 0, true);
				}
			}
		}
 
	/********************Forward Handlers************************/
		private function ForwardOver(event:MouseEvent):void {
			var obj:Object = event.currentTarget;
			obj.gotoAndStop('forward_over');
		}
		private function ForwardOut(event:MouseEvent):void {
			var obj:Object = event.currentTarget;
			obj.gotoAndStop('forward');
		}
		private function ForwardDown(event:MouseEvent):void {
			var obj:Object = event.currentTarget;
			obj.gotoAndStop('forward_down');
		}
		/*changes the List selection and then dispatches a fake ITEM_CLICK event.*/
		private function ForwardUp(event:MouseEvent):void {
			var obj:Object = event.currentTarget;
			obj.gotoAndStop('forward_over');
 
			if(playList.length > playList.selectedIndex + 1){
				playList.selectedIndex++;
				playList.scrollToSelected();
			} else {
				playList.selectedIndex = 0;
				playList.scrollToSelected();
			}
			playList.dispatchEvent(new ListEvent(ListEvent.ITEM_CLICK, false, true, 0, playList.selectedIndex, playList.selectedIndex, playList.selectedItem));
		}
	}
}

Je sais... rien que ça... mais bon...

Dans ce fichier AS, on demande de charger les données d'un fichier XML (playlist_1_1.xml)

Ce fichier XML est créé et/ou mis à jour grâce à une page PHP conteneur du player SWF. A chaque fois que la page est ouverte, php met à jour les données et le nom du fichier XML de type playlist_variable1_variable2.xml.

Pour créer et vérifier le lecteur j'ai donc fais des test avec le nom direct d'un fichier xml créé dynamiquement par ma page php. (playlist_1_1.xml) Bien entendu les deux variables ici sont 1 et 1.

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
public var position:Number;

		/*The constructor mainly sets up the event listeners, but it also
		starts loading the XML playlist file.*/
		public function Mp3Main() {
			position = 0;
			sndTrans = new SoundTransform(vol_mc.percent);
			url = new URLRequest("playlist_1_1.xml");
			xmlLoad = new URLLoader(url);
			xmlLoad.addEventListener(Event.COMPLETE, xmlComplete);
Dans mon fichier php j'ai une flashvars de type: flashvars=playlist_variable1_variable2.xml. Cela permet de créer dynamiquement le nom de mon fichier xml dans le conteneur.

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
<?php
	$data.="<object classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,28,0' width='550' height='400' title='player'>";
	$data.="<param name='movie' value='AS3MP3Player.swf'>";
	$data.="<param name='quality' value='high'>";
	$idalbum = '' . $row_album['id'] . '';
	$iduser = '' . $row_connexion['id'] . '';
	$data_object="<param FlashVars=\"xmlfile=playlist_$iduser_$idalbum.xml\">";
	$data_embed="FlashVars=\"xmlfile=playlist_$iduser_$idalbum.xml\"";
$data.=$data_object;
$data_end.="</object>";				
$data_emb.="<embed src='AS3MP3Player.swf' quality='high' autoplay='false' width='550' height='400' TYPE='application/x-shockwave-flash' pluginspage='http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash' ";
$data_emb.=$data_embed;
$data_emb.=">";
print $data;
print $data_emb;
print $data_end;
?>
L'objectif pour moi serait de pouvoir indiquer au fichier AS de récupérer cette flashvar qui contient le nom de mon fichier XML généré par php.

Si quelqu'un avait une petite idée là dessus, je suis preneur.

En vous remerciant par avance.

Tony.