/* Version: MPL 1.1 The contents of this file are subject to the Mozilla Public License Version 1.1 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.mozilla.org/MPL/ Software distributed under the License is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for the specific language governing rights and limitations under the License. The Original Code is mp3player (http://code.google.com/p/mp3player/). The Initial Developer of the Original Code is neolao (neolao@gmail.com). */ /** * Template for several mp3 * * @author neolao * @version 1.2.1 (04/01/2008) * @license http://creativecommons.org/licenses/by-sa/3.0/deed.fr */ class TemplateMulti extends ATemplate { // ------------------------------ VARIABLES -------------------------------- /** * Template width */ private var _width:Number = 200; /** * Template height */ private var _height:Number = 100; /** * Toolbar height */ private var _playerHeight:Number = 20; private var _backgroundSkin:String; private var _backgroundColor:Number; private var _backgroundColor1:Number = 0x7c7c7c; private var _backgroundColor2:Number = 0x000000; private var _buttonColor:Number = 0xffffff; private var _buttonOverColor:Number = 0xffff00; private var _sliderColor1:Number = 0xcccccc; private var _sliderColor2:Number = 0x888888; private var _sliderOverColor:Number = 0xeeee00; private var _textColor:Number = 0xffffff; private var _loadingColor:Number = 0xffff00; private var _playlistColor:Number = 0x000000; private var _playlistAlpha:Number = 50; private var _currentMp3Color:Number = 0xffff00; private var _scrollbarColor:Number = 0xffffff; private var _scrollbarOverColor:Number = 0xffff00; private var _showList:Boolean = true; private var _showSlider:Boolean = true; private var _title:Array; private var _showInfo:Boolean = false; private var _showVolume:Boolean = false; private var _volume:Number = 100; private var _volumeMax:Number = 200; private var _showLoading:String = "autohide"; // always, autohide, never private var _showPlaylistNumbers:Boolean = true; public var buttonWidth:Number = 26; public var volumeWidth:Number = 30; public var volumeHeight:Number = 6; public var sliderWidth:Number = 20; public var sliderHeight:Number = 10; private var _target:MovieClip = _root; private var _backgroundInstance:MovieClip; private var _previousButtonInstance:MovieClip; private var _playButtonInstance:MovieClip; private var _pauseButtonInstance:MovieClip; private var _stopButtonInstance:MovieClip; private var _infoButtonInstance:MovieClip; private var _infoPanel:MovieClip; private var _nextButtonInstance:MovieClip; private var _volumeButtonInstance:MovieClip; private var _separatorsInstance:MovieClip; private var _sliderInstance:MovieClip; private var _loadingInstance:MovieClip; private var _playlistInstance:MovieClip; private var _scrollbarInstance:MovieClip; private var _currentIndex:Number = 0; /*============================= CONSTRUCTEUR =============================*/ /*========================================================================*/ /** * Constructor */ public function TemplateMulti() { super(); // Initialisation du Stage Stage.scaleMode = "noScale"; Stage.align = "TL"; this._initVars(); if (!this._showList) { this._height = this._playerHeight; } this._initBackground(); this._initPreviousButton(); this._initPlayButton(); this._initPauseButton(); this._initStopButton(); this._initInfoButton(); this._initNextButton(); this._initVolumeButton(); var vMarginSlider:Number = this.buttonWidth*4; var vSeparators:Array = [this.buttonWidth, this.buttonWidth, this.buttonWidth, this.buttonWidth]; if (this._showInfo) { vMarginSlider += this.buttonWidth; vSeparators.push(this.buttonWidth); } if (this._showVolume) { vMarginSlider += this.volumeWidth; vSeparators.push(this.volumeWidth); } if (this._showSlider) { this._initSlider(vMarginSlider); } else { vMarginSlider -= this.buttonWidth; vSeparators.pop(); } this._createSeparators(vSeparators); // Si la playlist est générée avec un fichier // Alors il ne faut pas encore créer l'affichage de la playlist if (_root.playlist != undefined) { this._loadPlaylist(_root.playlist); } else { // Use postcast rss if (_root.playlistrss != undefined) { this._loadPlaylistRss(_root.playlistrss); } else { this._initPlaylist(); } } this._initInfoPanel(); // Raccourcis clavier var vPlayPause:Function = this.delegate(this, function() { if (this.player.isPlaying) { this.pauseRelease(); } else { this.playRelease(); } }); var vDecreaseVolume:Function = this.delegate(this, function() { var vVolume:Number = this._volume; vVolume -= 10; if (vVolume < 0) { vVolume = 0; } this.setVolume(vVolume); }); var vIncreaseVolume:Function = this.delegate(this, function() { var vVolume:Number = this._volume; vVolume += 10; if (vVolume > this._volumeMax) { vVolume = this._volumeMax; } this.setVolume(vVolume); }); // touche "Espace" this._addShortcut(32, vPlayPause); // touche "P" this._addShortcut(80, vPlayPause); // touche "S" this._addShortcut(83, this.delegate(this, function() { this.stopRelease(); })); // touche flèche gauche this._addShortcut(37, this.delegate(this, function() { this.player.setPosition(this.player.getPosition() - 5000); })); // touche flèche droite this._addShortcut(39, this.delegate(this, function() { this.player.setPosition(this.player.getPosition() + 5000); })); // touche flèche haut this._addShortcut(38, this.delegate(this, function() { if (this.player.hasPrevious) { this.previousRelease(); } })); // touche flèche bas this._addShortcut(40, this.delegate(this, function() { if (this.player.hasNext) { this.nextRelease(); } })); // touche "-" this._addShortcut(109, vDecreaseVolume); this._addShortcut(189, vDecreaseVolume); // touche "+" this._addShortcut(107, vIncreaseVolume); this._addShortcut(187, vIncreaseVolume); // touche "I" this._addShortcut(73, this.delegate(this, function() { this.infoRelease(); })); } /** * Launched by mtasc */ static function main():Void { // On vérifie s'il y a un fichier de configuration à charger if (_root.config != undefined) { // Fichier de configuration texte var vConfigLoad:LoadVars = new LoadVars(); vConfigLoad.onData = function(data:String) { if (data != undefined) { data = data.split("\r\n").join("\n"); var newdata:Array = data.split("\n"); for (var i=0; i 0) { // On peut scroller this.info_txt.text += sep; var textLength:Number = this.info_txt.length; this.info_txt.text = this.info_txt.text.substring(this.scrollMemo, textLength) + this.info_txt.text.substring(0, this.scrollMemo - 1); if (++this.waitScroll > 5) { this.scrollMemo += 1; this.waitScroll = 0; } this.scrollMemo = this.scrollMemo % (textLength); } }; } } /** * Initialisation du bouton Next */ private function _initNextButton() { // Création if (this._nextButtonInstance == undefined) { this._nextButtonInstance = this._target.createEmptyMovieClip("next_btn", this._target.getNextHighestDepth()); this._initButton(this._nextButtonInstance); } // Position this._nextButtonInstance._x = (this._showInfo)?this.buttonWidth*4:this.buttonWidth*3; // Action this._nextButtonInstance.area_mc.onRelease = this.delegate(this, this.nextRelease); // Icone this._nextButtonInstance.icon_mc.beginFill(this._buttonColor); this._nextButtonInstance.icon_mc.lineTo(0, 8); this._nextButtonInstance.icon_mc.lineTo(6, 4); this._nextButtonInstance.icon_mc.endFill(); this._nextButtonInstance.icon_mc.moveTo(6, 0); this._nextButtonInstance.icon_mc.beginFill(this._buttonColor); this._nextButtonInstance.icon_mc.lineTo(8, 0); this._nextButtonInstance.icon_mc.lineTo(8, 8); this._nextButtonInstance.icon_mc.lineTo(6, 8); this._nextButtonInstance.icon_mc.endFill(); this._nextButtonInstance.icon_mc._y = this._playerHeight/2 - this._nextButtonInstance.icon_mc._height/2; this._nextButtonInstance.icon_mc._x = this.buttonWidth/2 - this._nextButtonInstance.icon_mc._width/2; } /** * Initialisation du bouton Volume */ private function _initVolumeButton() { if (this._showVolume) { this._volumeButtonInstance = this._target.createEmptyMovieClip("volume_btn", this._target.getNextHighestDepth()); this._initButton(this._volumeButtonInstance, this.volumeWidth); // Position this._volumeButtonInstance._x = (this._showInfo)?this.buttonWidth*5:this.buttonWidth*4; this._volumeButtonInstance.area_mc.onPress = this.delegate(this, this._volumePress); this._volumeButtonInstance.area_mc.onRelease = this.delegate(this, this._volumeRelease); this._volumeButtonInstance.area_mc.onReleaseOutside = this.delegate(this, this._volumeRelease); // icone fond var vIconBackground:MovieClip = this._volumeButtonInstance.icon_mc.createEmptyMovieClip("background_mc", 1); vIconBackground.beginFill(this._buttonColor, 25); vIconBackground.moveTo(0, this.volumeHeight); vIconBackground.lineTo(this.volumeWidth - 8, this.volumeHeight); vIconBackground.lineTo(this.volumeWidth - 8, 0); vIconBackground.endFill(); vIconBackground._y = this._playerHeight/2 - vIconBackground._height/2; vIconBackground._x = this.volumeWidth/2 - vIconBackground._width/2; // icone this._updateVolume(); } } /** * Mise à jour du bouton Volume */ private function _updateVolume() { var vIcon:MovieClip; if (this._volumeButtonInstance.icon_mc.current_mc == undefined) { vIcon = this._volumeButtonInstance.icon_mc.createEmptyMovieClip("current_mc", 2); } else { vIcon = this._volumeButtonInstance.icon_mc.current_mc; } vIcon.clear(); if (this._volume > this._volumeMax) { this._volume = this._volumeMax; } var vWidth:Number = (this.volumeWidth - 8) * this._volume / this._volumeMax; var vRatio:Number = this._volume / this._volumeMax; vIcon.beginFill(this._buttonColor); vIcon.moveTo(0, this.volumeHeight); vIcon.lineTo(vWidth, this.volumeHeight); vIcon.lineTo(vWidth, this.volumeHeight - this.volumeHeight * vRatio); vIcon.endFill(); vIcon._y = vIcon._parent.background_mc._y; vIcon._x = vIcon._parent.background_mc._x; } /** * Le enterFrame pendant l'appui du bouton Volume */ private function _volumeEnterFrame() { var xmouse:Number = this._volumeButtonInstance.icon_mc.current_mc._xmouse; var max:Number = this._volumeButtonInstance.icon_mc.background_mc._width; if (xmouse < 0) { xmouse = 0; } if (xmouse > max) { xmouse = max; } var volume:Number = xmouse * this._volumeMax / max; this.setVolume(volume); } /** * On appuie sur le bouton Volume */ private function _volumePress() { this._volumeButtonInstance.onEnterFrame = this.delegate(this, this._volumeEnterFrame); } /** * On relâche le bouton Volume */ private function _volumeRelease() { delete this._volumeButtonInstance.onEnterFrame; } /** * Initialisation de la barre * * @param pMargin La marge gauche de la barre */ private function _initSlider(pMargin:Number) { if (this._sliderInstance == undefined) { this._sliderInstance = this._target.createEmptyMovieClip("slider_mc", this._target.getNextHighestDepth()); } // calcul de la taille var vMargin:Number = pMargin; vMargin += 10; this._sliderInstance._x = vMargin; this._sliderInstance.width = this._width - vMargin - 10; // barre this._sliderInstance.barBg_mc.removeMovieClip(); var vBarBg:MovieClip = this._sliderInstance.createEmptyMovieClip("barBg_mc", this._sliderInstance.getNextHighestDepth()); vBarBg.beginFill(0xcccccc, 25); vBarBg.lineTo(this._sliderInstance.width, 0); vBarBg.lineTo(this._sliderInstance.width, 1); vBarBg.lineTo(0, 1); vBarBg.endFill(); vBarBg.beginFill(0x666666, 25); vBarBg.moveTo(0, 0); vBarBg.lineTo(0, -1); vBarBg.lineTo(this._sliderInstance.width, -1); vBarBg.lineTo(this._sliderInstance.width, 0); vBarBg.endFill(); vBarBg._y = this._playerHeight / 2; // barre de chargement this._loadingInstance = this._sliderInstance.createEmptyMovieClip("loading_mc", this._sliderInstance.getNextHighestDepth()); this._loadingInstance.beginFill(this._loadingColor, 75); this._loadingInstance.moveTo(0, -1) this._loadingInstance.lineTo(this._sliderInstance.width, -1); this._loadingInstance.lineTo(this._sliderInstance.width, 1); this._loadingInstance.lineTo(0, 1); this._loadingInstance.endFill(); this._loadingInstance._y = this._playerHeight / 2; this._loadingInstance._xscale = 0; this._loadingInstance._visible = false; // barre slider var vSlider:MovieClip = this._sliderInstance.createEmptyMovieClip("bar_mc", this._sliderInstance.getNextHighestDepth()); vSlider.parent = this; vSlider.margin = vMargin; vSlider.width = this.sliderWidth; vSlider.barWidth = this._sliderInstance.width; vSlider.color = new Color(vSlider); vSlider.onRollOver = function() { this.color.setRGB(this.parent._sliderOverColor); }; vSlider.onRollOut = function() { var transform:Object = {ra: 100, rb: 0, ga: 100, gb: 0, ba: 100, bb: 0, aa: 100, ab: 0}; this.color.setTransform(transform); }; vSlider.onPress = function() { this.startDrag(false, 0, this._y, this.barWidth - this.width, this._y); delete this.parent._sliderInstance.onEnterFrame; }; vSlider.onRelease = vSlider.onReleaseOutside = function() { this.stopDrag(); var position:Number = this._x / (this.barWidth - this.width) * this.parent.player.getDuration(); this.parent.player.setPosition(position); if (this.parent.player.isPlaying) { this.parent.playRelease(); } }; vSlider.beginGradientFill("linear", [this._sliderColor1, this._sliderColor2], [100,100], [50,150], {matrixType:"box", x:0, y:0, w:this.sliderWidth, h:this.sliderHeight, r:Math.PI/2}); vSlider.moveTo(0, 4); vSlider.lineTo(0, this.sliderHeight - 4); vSlider.curveTo(0, this.sliderHeight, 4, this.sliderHeight); vSlider.lineTo(this.sliderWidth - 4, this.sliderHeight); vSlider.curveTo(this.sliderWidth, this.sliderHeight, this.sliderWidth, this.sliderHeight - 4); vSlider.lineTo(this.sliderWidth, 4); vSlider.curveTo(this.sliderWidth, 0, this.sliderWidth - 4, 0); vSlider.lineTo(4, 0); vSlider.curveTo(0, 0, 0, 4); vSlider.endFill(); vSlider._y = this._playerHeight/2 - this.sliderHeight / 2; } /** * Chargement */ private function _loading() { var objLoading:Object = this.player.getLoading(); this._loadingInstance._xscale = (objLoading.percent >= 1)?objLoading.percent:0; if (objLoading.percent == 100) { if (this._showLoading != "always") { this._loadingInstance._visible = false; } delete this._loadingInstance.onEnterFrame; } } /** * Le enterFrame du slider */ private function _sliderEnterFrame() { var total:Number = (this._sliderInstance.loading_mc._visible)?this._sliderInstance.loading_mc._width:this._sliderInstance.width - this.sliderWidth; var position:Number = Math.round(this.player.getPosition()/this.player.getDuration() * total); this._sliderInstance.bar_mc._x = position; if (!this.player.isPlaying && position == total) { this.stopRelease(); } if (this._currentIndex != this.player.index) { this._currentIndex = this.player.index; this.updatePlaylist(); } } /** * Initialisation de la playlist * @return true */ private function _initPlaylist():Boolean { var totalMp3:Number = _root.mp3.split("|").length; var version:String = System.capabilities.version; if (version.indexOf("MAC") != -1) { totalMp3++; } // On vérifie si on affiche la playlist ou pas if (!this._showList) { return true; } // Création this._playlistInstance = this._target.createEmptyMovieClip("playlist_mc", this._target.getNextHighestDepth()); // Position this._playlistInstance._y = this._playerHeight; // Fond if (this._backgroundSkin == undefined) { this._playlistInstance.moveTo(5, 0); this._playlistInstance.beginFill(this._playlistColor, this._playlistAlpha); this._playlistInstance.lineTo(this._width - 5, 0); this._playlistInstance.lineTo(this._width - 5, this._height - this._playerHeight - 5); this._playlistInstance.lineTo(5, this._height - this._playerHeight - 5); this._playlistInstance.endFill(); } // Champ de texte this._playlistInstance.createTextField("list_txt", 1, 5, 0, this._width - 20, this._height - this._playerHeight); //this._playlistInstance.list_txt.selectable = false; this._playlistInstance.list_txt.html = true; // Remplissage du champ pour vérifier si ca scroll this._playlistInstance.list_txt.text = ""; for (var i:Number=0; i 1) { this._scrollbarInstance = this._playlistInstance.createEmptyMovieClip("scrollbar_mc", 2); this._scrollbarInstance.beginFill(this._scrollbarColor); this._scrollbarInstance.lineTo(4, 0); this._scrollbarInstance.lineTo(4, this._height - this._playerHeight - 5); this._scrollbarInstance.lineTo(0, this._height - this._playerHeight - 5); this._scrollbarInstance.endFill(); this._scrollbarInstance._x = this._width - 10; this._scrollbarInstance._yscale = (totalMp3 - this._playlistInstance.list_txt.maxscroll + 1)/totalMp3 * 100; this._scrollbarInstance.max = (this._height - this._playerHeight - 5) - this._scrollbarInstance._height; this._scrollbarInstance.step = this._scrollbarInstance.max / (this._playlistInstance.list_txt.maxscroll - 1); this._scrollbarInstance.color = new Color(this._scrollbarInstance); this._scrollbarInstance.colorOver = this._scrollbarOverColor; this._scrollbarInstance.onRollOver = function() { this.color.setRGB(this.colorOver); }; this._scrollbarInstance.onRollOut = function() { var transform:Object = {ra: 100, rb: 0, ga: 100, gb: 0, ba: 100, bb: 0, aa: 100, ab: 0}; this.color.setTransform(transform); }; this._scrollbarInstance.onPress = function() { this.onEnterFrameAuto = this.onEnterFrame; this.startDrag(false, this._x, 0, this._x, this.max); this.onEnterFrame = function() { this._parent.list_txt.scroll = Math.floor((this._y+1) / this.step) + 1; } } this._scrollbarInstance.onRelease = this._scrollbarInstance.onReleaseOutside = function() { this.stopDrag(); this.onEnterFrame = this.onEnterFrameAuto; } this._scrollbarInstance.onEnterFrame = function() { if (this._parent.list_txt.scroll == this._parent.list_txt.maxscroll) { this._y = this.max; } else { this._y = (this._parent.list_txt.scroll - 1) * this.step; } } } // Mise à jour de la playlist en permanence this._playlistInstance.waitScroll = 0; this._playlistInstance.intervalScroll = 0; this._playlistInstance.scrollMemo = 0; this._playlistInstance.onEnterFrame = this.delegate(this, this.updatePlaylist); return true; } /*===================== FIN = METHODES PRIVEES = FIN =====================*/ /*========================================================================*/ /*========================== METHODES PUBLIQUES ==========================*/ /*========================================================================*/ /** * Mise à jour de la playlist * * @param pAutoScroll Indique qu'il faut scroller au bon endroit de la liste */ public function updatePlaylist(pAutoScroll:Boolean) { var text:String = "" var title_tmp:String; var color:String = this._textColor.toString(16); if (this.player.playlist.length > 0) { text = ""; } else { text = "Liste vide"; } // Génération des pistes for (var i:Number=0; i"; text += ""; if (this._showPlaylistNumbers) { text += (i+1) + " - "; } // titre de la piste if (this._title[i] != undefined) { title_tmp = this._title[i]; } else { title_tmp = this.player.playlist[i]; } // Défilement automatique pour la piste sélectionnée this._playlistInstance.textfield_tmp.text = title_tmp; if (i == this.player.index && this._playlistInstance.textfield_tmp.maxhscroll > 0) { // On peut scroller title_tmp += " - "; var textLength:Number = title_tmp.length; if (++this._playlistInstance.waitScroll < 40) { this._playlistInstance.intervalScroll = 0; } title_tmp = title_tmp.substring(this._playlistInstance.scrollMemo, textLength) + title_tmp.substring(0, this._playlistInstance.scrollMemo - 1); if (++this._playlistInstance.intervalScroll > 5) { this._playlistInstance.scrollMemo += 1; this._playlistInstance.intervalScroll = 0; } this._playlistInstance.scrollMemo = this._playlistInstance.scrollMemo % (textLength); } this._playlistInstance.textfield_tmp.text = ""; // La fin text += title_tmp; text += "\n"; text += ""; text += ""; } this._playlistInstance.list_txt.htmlText = text; // Scroll automatique sur l'élément if (pAutoScroll && this._playlistInstance.list_txt.maxscroll > 1) { this._playlistInstance.list_txt.scroll = this._playlistInstance.list_txt.maxscroll - (this.player.playlist.length - 1 - this.player.index); } // Boutons Previous et Next this._enableButton(this._nextButtonInstance, this.player.hasNext); this._enableButton(this._previousButtonInstance, this.player.hasPrevious); } /** * Action sur le bouton Previous */ public function previousRelease() { this.player.previous(); this._currentIndex = this.player.index; this.updatePlaylist(true); } /** * Action sur le bouton Play */ public function playRelease() { super.playRelease(); this._enableButton(this._playButtonInstance, false, true); this._enableButton(this._pauseButtonInstance, true); this._enableButton(this._stopButtonInstance, true); this._sliderInstance.onEnterFrame = this.delegate(this, this._sliderEnterFrame); this._currentIndex = this.player.index; this._playlistInstance.waitScroll = 0; this._playlistInstance.intervalScroll = 0; this._playlistInstance.scrollMemo = 0; this.updatePlaylist(true); } /** * Action sur le bouton Pause */ public function pauseRelease() { super.pauseRelease(); this._enableButton(this._pauseButtonInstance, false, true); this._enableButton(this._playButtonInstance, true); this.updatePlaylist(); } /** * Action sur le bouton Stop */ public function stopRelease() { super.stopRelease(); this._enableButton(this._stopButtonInstance, false); this._enableButton(this._pauseButtonInstance, false, true); this._enableButton(this._playButtonInstance, true); delete this._sliderInstance.onEnterFrame; this._sliderInstance.bar_mc._x = 0; this.updatePlaylist(); } /** * Action sur le bouton info */ public function infoRelease() { if (this._infoPanel._visible = !this._infoPanel._visible) { this._infoPanel.onEnterFrame = this._infoPanel.update; } else { delete this._infoPanel.onEnterFrame; } } /** * Action sur le bouton Next */ public function nextRelease() { this.player.next(); this._currentIndex = this.player.index; this.updatePlaylist(true); } /** * Modifie le volume * * Le maximum est de 200 * @param pVolume Le nouveau volume */ public function setVolume(pVolume:Number) { this._volume = pVolume; this._updateVolume(); this.player.setVolume(pVolume); } /** * Affichage du chargement */ public function startLoading():Void { super.startLoading(); this._loadingInstance.onEnterFrame = this.delegate(this, this._loading); if (this._showLoading != "never") { this._loadingInstance._visible = true; } } /*==================== FIN = METHODES PUBLIQUES = FIN ====================*/ /*========================================================================*/ }