IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

ActionScript 3 Discussion :

mode autoplay player flash AS3


Sujet :

ActionScript 3

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Nouveau membre du Club
    Homme Profil pro
    Intégrateur Web
    Inscrit en
    Mai 2012
    Messages
    4
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Intégrateur Web

    Informations forums :
    Inscription : Mai 2012
    Messages : 4
    Par défaut mode autoplay player flash AS3
    Bonjour à tous

    Je m'en remet à vous parce que je trouve pas de solution à mon problème, j'ai fait l'acquisition d'un module de player de music flash en AS3 qui convient à ce que j'ai besoin sauf que celui-ci dès que la page web est chargé commence à jouer la musique alors que ce que j'aimerais c'est de pouvoir faire en sorte que la musique ne commence pas automatiquement. Je me suis renseigné et apparemment il s'agit d'une histoire d'autoplay sauf que je trouve nul part cette fonction dans le code et que je n'arrive pas à modifier le code pour que ça puisse réaliser ce que je veux alors si vous pouviez m'aider...

    Voici le code du fichier XML

    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
    import flash.events.Event;
    	import flash.events.EventDispatcher;
    	import flash.events.IOErrorEvent;
    	import flash.net.URLLoader;
    	import flash.net.URLRequest;	
     
    	/**
    	 * A class for loading external xml files to the
    	 * memory and fire appropriate events when parsing process
    	 * is completed.
    	 */
    	public class XMLLoader extends EventDispatcher {
     
    		// Indicates whether the cache killer is turned on.
    		public static const CACHE_KILLER_ON:Boolean = false;
     
    		// The name of the event to be fired when loading is completed
    		public static const XML_LOADED:String = "xmlLoaded";
     
    		// The xml data to be returned
    		private var xml:XML;
     
    		// The url of the xml file
    		private var url:String;
     
    		// A URLRequest instance to be used during loading process
    		private var urlRequest:URLRequest;
     
    		// A URLLoader instance for loading the xml file
    		private var urlLoader:URLLoader;
     
    		public function XMLLoader(url:String) {
     
    			this.url = url;
     
    		}
     
    		public function load():void {					
     
    			// Create a new URLRequest object, pass our url to it
    			if (CACHE_KILLER_ON) {
    				urlRequest = new URLRequest(url + "?cache=" + new Date().getTime());
    			} else {
    				urlRequest = new URLRequest(url);
    			}
     
    			// Create the URLLoader object and start loading
    			urlLoader = new URLLoader(urlRequest);
     
    			// Start listening for Event.COMPLETE
    			urlLoader.addEventListener(Event.COMPLETE, onComplete, false, 0, true);
     
    			// Start listening for IOErrorEvent.IO_ERROR
    			urlLoader.addEventListener(IOErrorEvent.IO_ERROR, onIOError, false, 0, true);
     
     
     
    		}
     
    		/**
    		 * Returns the XML data when parsing process is completed.
    		 */
    		public function getXML():XML {
     
    			return xml;
     
    		}
     
    		/**
    		 * This method is called when parsing xml is completed. It
    		 * creates a new XML object and set the data read then fires
    		 * events to all listeners.
    		 */
    		private function onComplete(evt:Event):void {
     
    			xml = new XML(evt.target.data);			
    			dispatchEvent(new Event(XML_LOADED));
     
    		}
     
    		/**
    		 * This method is called when an error occurs during loading
    		 * process.
    		 */
    		private function onIOError(evt:IOErrorEvent):void {
     
    			trace("An error occured during loading XML : " + evt.text);
    			trace("** Launch the application within your browser or turn off the cache killer. **");
     
    		}		
     
    	}
     
    }
    et voici le code AS3 du player

    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
    import flash.display.MovieClip;
    	import flash.events.Event;
    	import flash.events.IOErrorEvent;
    	import flash.events.MouseEvent;
    	import flash.geom.ColorTransform;
    	import flash.media.Sound;
    	import flash.media.SoundChannel;
    	import flash.media.SoundMixer;
    	import flash.net.URLRequest;
    	import flash.utils.ByteArray;
    	import flash.text.TextField;
     
    	public class MP3Player extends MovieClip {
     
    		// Location of the config xml file
    		public static const CONFIG_XML_URL:String = "xml/config.xml";
     
    		// URL of the mp3 file
    		public static var MP3_URL:String = "mp3/track.mp3";
     
    		// Main color for the mp3 player
    		public static var MAIN_COLOR:uint = 0xFF0000;
     
    		// An XMLLoader to load the configuration file
    		private var xmlLoader:XMLLoader;
     
    		// Sound object to be played
    		private var mp3:Sound = new Sound();
     
    		// A sound channel to play the sound object
    		private var channel:SoundChannel;
     
    		// Holds the pause position
    		private var pausePos:Number;
     
    		// A byte array to read spectrum
    		private var bytes:ByteArray = new ByteArray();
     
    		// Indicates whether the mp3 player is playing or not.
    		private var _isPlaying:Boolean = false;
     
    		// Holds the previous label color
    		private var _prevColor:uint;		
     
    		public function MP3Player() {
     
    			// Initialize the player
    			init();
     
    		}
     
    		/**
    		 * Initializes the player.
    		 */
    		private function init():void {
     
    			// Use as a button
    			useHandCursor = true;
    			buttonMode = true;
    			mouseChildren = false;
    			equalizer.alpha = 0;
     
    			// Add necessary event listeners
    			addEventListener(Event.ENTER_FRAME, onEnterFrame, false, 0, true);
    			addEventListener(MouseEvent.MOUSE_DOWN, onMouseDown, false, 0, true);
    			addEventListener(MouseEvent.MOUSE_OVER, onMouseOver, false, 0, true);
    			addEventListener(MouseEvent.MOUSE_OUT, onMouseOut, false, 0, true);
    			loadConfig();
     
    		}
     
    		/**
    		 * Sets the color of the player to the given parameter.
    		 */
    		public function setColor(color:uint):void {
     
    			MAIN_COLOR = color;
     
    			// Change the color of the equalizer
    			var colorTransform:ColorTransform = equalizer.transform.colorTransform;
    			colorTransform.color = MAIN_COLOR;
    			equalizer.transform.colorTransform = colorTransform;
     
    		}
     
     
    		/**
    		 * Loads the configuration file to the memory.
    		 */
    		private function loadConfig() {
     
    			// Start loading the config.xml file
    			xmlLoader = new XMLLoader(CONFIG_XML_URL);
    			xmlLoader.addEventListener(XMLLoader.XML_LOADED, onXMLLoaded);
    			xmlLoader.load();
     
    		}
     
    		/**
    		 * This method is called when the xml file is loaded to the memory.
    		 */
    		private function onXMLLoaded(evt:Event):void {
     
    			// Get configuration parameters
    			var xml:XML = xmlLoader.getXML();
    			MP3_URL = xml.@mp3URL;
    			MAIN_COLOR = xml.@color;
     
    			// Change the color of the equalizer
    			equalizer.alpha = 1;
    			setColor(MAIN_COLOR);
     
    			// Start loading the mp3
    			loadMP3();
     
    		}
     
    		/**
    		 * Start loading the mp3 file.
    		 */
    		private function loadMP3():void {
     
    			mp3.load(new URLRequest(MP3_URL));
    			mp3.addEventListener(IOErrorEvent.IO_ERROR, onIOError, false, 0, true);
    			channel = mp3.play();
    			channel.addEventListener(Event.SOUND_COMPLETE, onSoundComplete, false, 0, true);			
    			_isPlaying = true;
     
    		}
     
     
    		/**
    		 * This method is called whenever a new enter frame event occurs.
    		 */
    		private function onEnterFrame(evt:Event):void {
     
    			try {
    				SoundMixer.computeSpectrum(bytes, true, 0);
    			} catch (e:Error) {
    			}
     
    			equalizer.update(bytes);
     
    		}
     
    		/**
    		 * This method is called when playing the sound is finished.
    		 */
    		private function onSoundComplete(evt:Event):void {
     
    			// Loop
    			channel = mp3.play();
    			channel.addEventListener(Event.SOUND_COMPLETE, onSoundComplete, false, 0, true);
    			_isPlaying = true;
     
    		}
     
    		/**
    		 * This method is called when the mouse is over the mp3 player.
    		 */
    		private function onMouseOver(evt:MouseEvent):void {
     
    			// Change the color of the equalizer
    			_prevColor = label.textColor;
    			label.textColor = MAIN_COLOR;
     
    		}
     
    		/**
    		 * This method is called when the mouse leaves the mp3 player.
    		 */
    		private function onMouseOut(evt:MouseEvent):void {
     
    			label.textColor = _prevColor;
     
    		}
     
    		/**
    		 * This method is called when the mouse is clicked on the mp3 player.
    		 */
    		private function onMouseDown(evt:MouseEvent):void {
     
    			if (_isPlaying) {
    				pausePos = channel.position;
    				channel.stop();
    				_isPlaying = false;
    				label.text = "MUSIC OFF";				
    			} else {
    				channel = mp3.play(pausePos);
    				channel.addEventListener(Event.SOUND_COMPLETE, onSoundComplete, false, 0, true);
    				_isPlaying = true;
    				label.text = "MUSIC ON";
    			}
     
    		}
     
    		/**
    		 * This method is called if an IO error occurs.
    		 */
    		private function onIOError(evt:IOErrorEvent):void {
    		}
     
    	}
     
    }
    Je suis sur qu'il y a moyen de modifier un peu le code pour que le player flash ne se déclenche pas automatiquement malheureusement toute mes tentatives ont été infructueuses et à part racheter un player ce qui m’ennuierai parce que celui ci me convient bien au niveau du graphisme je ne sais pas quoi faire.

    Merci par avance.

  2. #2
    Membre actif
    Homme Profil pro
    Étudiant
    Inscrit en
    Septembre 2011
    Messages
    27
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Gard (Languedoc Roussillon)

    Informations professionnelles :
    Activité : Étudiant
    Secteur : Bâtiment

    Informations forums :
    Inscription : Septembre 2011
    Messages : 27
    Par défaut
    il semble lancé avec "loadMP3();"

    a partir de

    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
    private function onXMLLoaded(evt:Event):void {
     
    // Get configuration parameters
    var xml:XML = xmlLoader.getXML();
    MP3_URL = xml.@mp3URL;
    MAIN_COLOR = xml.@color;
     
    // Change the color of the equalizer
    equalizer.alpha = 1;
    setColor(MAIN_COLOR);
     
    // Start loading the mp3
    loadMP3();
     
    }

  3. #3
    Nouveau membre du Club
    Homme Profil pro
    Intégrateur Web
    Inscrit en
    Mai 2012
    Messages
    4
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Intégrateur Web

    Informations forums :
    Inscription : Mai 2012
    Messages : 4
    Par défaut
    On m'a donné la réponse sur un autre forum voici les modifications qu'il fallait apporter pour que ça fonctionne

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    private function loadMP3():void {
     
    mp3.load(new URLRequest(MP3_URL));
    mp3.addEventListener(IOErrorEvent.IO_ERROR, onIOError, false, 0, true);
    //channel = mp3.play();
    //channel.addEventListener(Event.SOUND_COMPLETE, onSoundComplete, false, 0, true);
    _isPlaying = false;
     
    }

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Comment activer le mode debug du Flash Player
    Par ToniConti dans le forum Flex
    Réponses: 3
    Dernier message: 11/08/2010, 12h11
  2. Player flash persistant
    Par The Nux dans le forum Général JavaScript
    Réponses: 2
    Dernier message: 22/01/2007, 09h45
  3. Réponses: 2
    Dernier message: 29/12/2006, 21h33
  4. Réponses: 4
    Dernier message: 13/06/2006, 10h20
  5. Player flash sous linux ?
    Par Michaël dans le forum Applications et environnements graphiques
    Réponses: 11
    Dernier message: 24/07/2004, 22h09

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo