我编写了一个简单的XML驱动MP3播放器。我使用过Sound和SoundChannel对象和方法,但我找不到一种方法来制作进度条。
我不需要加载进度我需要一个歌曲进度状态栏。
Canbd有人帮帮我吗?
感谢。
更新:
Theres是代码。
var musicReq: URLRequest; var thumbReq: URLRequest; var music:Sound = new Sound(); var sndC:SoundChannel; var currentSnd:Sound = music; var position:Number; var currentIndex:Number = 0; var songPaused:Boolean; var songStopped:Boolean; var lineClr:uint; var changeClr:Boolean; var xml:XML; var songList:XMLList; var loader:URLLoader = new URLLoader(); loader.addEventListener(Event.COMPLETE, Loaded); loader.load(new URLRequest("musiclist.xml")); var thumbHd:MovieClip = new MovieClip(); thumbHd.x = 50; thumbHd.y = 70; addChild(thumbHd); function Loaded(e:Event):void{ xml = new XML(e.target.data); songList = xml.song; musicReq = new URLRequest(songList[0].url); thumbReq = new URLRequest(songList[0].thumb); music.load(musicReq); sndC = music.play(); title_txt.text = songList[0].title + " - " + songList[0].artist; loadThumb(); sndC.addEventListener(Event.SOUND_COMPLETE, nextSong); } function loadThumb():void{ var thumbLoader:Loader = new Loader(); thumbReq = new URLRequest(songList[currentIndex].thumb); thumbLoader.load(thumbReq); thumbLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, thumbLoaded); } function thumbLoaded(e:Event):void { var thumb:Bitmap = (Bitmap)(e.target.content); var holder:MovieClip = thumbHd; holder.addChild(thumb); } prevBtn.addEventListener(MouseEvent.CLICK, prevSong); nextBtn.addEventListener(MouseEvent.CLICK, nextSong); playBtn.addEventListener(MouseEvent.CLICK, playSong); function prevSong(e:Event):void{ if(currentIndex > 0){ currentIndex--; } else{ currentIndex = songList.length() - 1; } var prevReq:URLRequest = new URLRequest(songList[currentIndex].url); var prevPlay:Sound = new Sound(prevReq); sndC.stop(); title_txt.text = songList[currentIndex].title + " - " + songList[currentIndex].artist; sndC = prevPlay.play(); currentSnd = prevPlay; songPaused = false; loadThumb(); sndC.addEventListener(Event.SOUND_COMPLETE, nextSong); } function nextSong(e:Event):void { if(currentIndex
这里是长度和位置的代码。它在MovieClip中。这就是我使用绝对路径找到Sound对象的原因。
this.addEventListener(Event.ENTER_FRAME, moveSpeaker);
var initWidth:Number = this.SpkCone.width;
var initHeight:Number = this.SpkCone.height;
var rootObj:Object = root;
function moveSpeaker(eventArgs:Event)
{
var average:Number = ((rootObj.audioPlayer_mc.sndC.leftPeak + rootObj.audioPlayer_mc.sndC.rightPeak) / 2) * 10;
// trace(average);
// trace(initWidth + ":" + initHeight);
trace(rootObj.audioPlayer_mc.sndC.position + "/" + rootObj.audioPlayer_mc.music.length);
this.SpkCone.width = initWidth + average;
this.SpkCone.height = initHeight + average;
}
答案 0 :(得分:2)
您可以使用以下方法获取标准化浮点值(完成百分比):SoundChannel.position / Sound.length。然后,您可以将该值用作声音播放进度指示器的标量。
Psuedo代码:
// -- set the x scale of the progress bar to the percent complete
progbar.scaleX = channel.position / sound.length;
答案 1 :(得分:0)
Sound类有一个“length”属性,表示声音的长度,SoundChannel有一个“position”属性,表示当前正在播放的声音的位置。使用这两个属性作为ProgressBar组件的数据。
答案 2 :(得分:0)
你必须听完整个事件,并在其中将scaleX设置为1。