+++ /dev/null
-/*\r
- * Ext JS Library 0.30\r
- * Copyright(c) 2006-2009, Ext JS, LLC.\r
- * licensing@extjs.com\r
- * \r
- * http://extjs.com/license\r
- */\r
-\r
-Ext.ns('Ext.air');\r
-\r
-Ext.air.MusicPlayer = Ext.extend(Ext.util.Observable, {\r
- /**\r
- * The currently active Sound. Read-only.\r
- * @type air.Sound\r
- * @property activeSound\r
- */\r
- activeSound: null,\r
- /**\r
- * The currently active SoundChannel. Read-only.\r
- * @type air.SoundChannel\r
- * @property activeChannel\r
- */\r
- activeChannel: null,\r
- /**\r
- * The currently active Transform. Read-only.\r
- * @type air.SoundTransform\r
- * @property activeTransform\r
- */\r
- activeTransform: new air.SoundTransform(1, 0),\r
- // private \r
- pausePosition: 0,\r
- /**\r
- * @cfg {Number} progressInterval\r
- * How often to fire the progress event when playing music in milliseconds\r
- * Defaults to 500.\r
- */\r
- progressInterval: 500,\r
- \r
- constructor: function(config) {\r
- config = config || {};\r
- Ext.apply(this, config);\r
- \r
- this.addEvents(\r
- /**\r
- * @event stop\r
- */\r
- 'stop',\r
- /**\r
- * @event pause\r
- */\r
- 'pause',\r
- /**\r
- * @event play\r
- */\r
- 'play',\r
- /**\r
- * @event load\r
- */\r
- 'load',\r
- /**\r
- * @event id3info\r
- */\r
- 'id3info',\r
- /**\r
- * @event complete\r
- */\r
- 'complete',\r
- /**\r
- * @event progress\r
- */\r
- 'progress',\r
- /**\r
- * @event skip\r
- */\r
- 'skip'\r
- );\r
- \r
- Ext.air.MusicPlayer.superclass.constructor.call(this, config);\r
- this.onSoundFinishedDelegate = this.onSoundFinished.createDelegate(this);\r
- this.onSoundLoadDelegate = this.onSoundLoad.createDelegate(this);\r
- this.onSoundID3LoadDelegate = this.onSoundID3Load.createDelegate(this);\r
-\r
- Ext.TaskMgr.start({\r
- run: this.notifyProgress,\r
- scope: this,\r
- interval: this.progressInterval\r
- }); \r
- }, \r
-\r
- /**\r
- * Adjust the volume\r
- * @param {Object} percent\r
- * Ranges from 0 to 1 specifying volume of sound.\r
- */\r
- adjustVolume: function(percent) {\r
- this.activeTransform.volume = percent;\r
- if (this.activeChannel) { \r
- this.activeChannel.soundTransform = this.activeTransform; \r
- } \r
- },\r
- /**\r
- * Stop the player\r
- */\r
- stop: function() {\r
- this.pausePosition = 0; \r
- if (this.activeChannel) {\r
- this.activeChannel.stop(); \r
- this.activeChannel = null; \r
- } \r
- if (this.activeSound) {\r
- this.activeSound.removeEventListener(air.Event.COMPLETE, this.onSoundLoadDelegate);\r
- this.activeSound.removeEventListener(air.Event.ID3, this.onSoundID3LoadDelegate);\r
- this.activeSound.removeEventListener(air.Event.SOUND_COMPLETE, this.onSoundFinishedDelegate); \r
- }\r
- },\r
- /**\r
- * Pause the player if there is an activeChannel\r
- */\r
- pause: function() {\r
- if (this.activeChannel) {\r
- this.pausePosition = this.activeChannel.position;\r
- this.activeChannel.stop(); \r
- } \r
- },\r
- /**\r
- * Play a sound, if no url is specified will attempt to resume the activeSound\r
- * @param {String} url (optional)\r
- * Url resource to play\r
- */\r
- play: function(url) {\r
- if (url) { \r
- this.stop(); \r
- var req = new air.URLRequest(url);\r
- this.activeSound = new air.Sound();\r
- this.activeSound.addEventListener(air.Event.SOUND_COMPLETE, this.onSoundFinishedDelegate); \r
- this.activeSound.addEventListener(air.Event.COMPLETE, this.onSoundLoadDelegate); \r
- this.activeSound.addEventListener(air.Event.ID3, this.onSoundID3LoadDelegate);\r
- this.activeSound.load(req); \r
- } else {\r
- this.onSoundLoad(); \r
- } \r
- },\r
- \r
- /**\r
- * Skip to a specific position in the song currently playing.\r
- * @param {Object} pos\r
- */\r
- skipTo: function(pos) {\r
- if (this.activeChannel) {\r
- this.activeChannel.stop(); \r
- this.activeChannel = this.activeSound.play(pos); \r
- this.activeChannel.soundTransform = this.activeTransform; \r
- this.fireEvent('skip', this.activeChannel, this.activeSound, pos);\r
- }\r
- },\r
- \r
- /**\r
- * Returns whether or not there is an active SoundChannel.\r
- */\r
- hasActiveChannel: function() {\r
- return !!this.activeChannel;\r
- },\r
- \r
- // private\r
- onSoundLoad: function(event) {\r
- if (this.activeSound) {\r
- if (this.activeChannel) {\r
- this.activeChannel.stop();\r
- }\r
- this.activeChannel = this.activeSound.play(this.pausePosition);\r
- this.activeChannel.soundTransform = this.activeTransform;\r
- this.fireEvent('load', this.activeChannel, this.activeSound);\r
- } \r
- },\r
- // private\r
- onSoundFinished: function(event) {\r
- // relay AIR event\r
- this.fireEvent('complete', event);\r
- },\r
- // private\r
- onSoundID3Load: function(event) {\r
- this.activeSound.removeEventListener(air.Event.ID3, this.onSoundID3LoadDelegate); \r
- var id3 = event.target.id3; \r
- this.fireEvent('id3info', id3);\r
- },\r
- // private\r
- notifyProgress: function() {\r
- if (this.activeChannel && this.activeSound) {\r
- var playbackPercent = 100 * (this.activeChannel.position / this.activeSound.length); \r
- // SOUND_COMPLETE does not seem to work consistently.\r
- if (playbackPercent > 99.7) {\r
- this.onSoundFinished(); \r
- } else {\r
- this.fireEvent('progress', this.activeChannel, this.activeSound);\r
- } \r
- } \r
- } \r
-});
\ No newline at end of file