Actionscript 3 as3 mp3播放器无法加载某些mp3文件
正如标题中所说,我正试图为我的网站制作mp3播放器,但我遇到了一些麻烦。我的代码看起来是这样的(它处于测试和开发阶段,所以,尽量不要关注开发阶段的事情) 问题是我的网络浏览器和其他一些flash mp3播放器可以打开“”,而我的播放器却不能。但是,可以打开、播放、重播其他文件“” 我注意到我无法打开的文件有一些不同的标题(它没有内容长度标题)。但是,我再次尝试了其他一些没有内容长度头的文件,并且可以打开它 我不知道我错在哪里…:D帮助,并提前感谢!:)Actionscript 3 as3 mp3播放器无法加载某些mp3文件,actionscript-3,flash,mp3,Actionscript 3,Flash,Mp3,正如标题中所说,我正试图为我的网站制作mp3播放器,但我遇到了一些麻烦。我的代码看起来是这样的(它处于测试和开发阶段,所以,尽量不要关注开发阶段的事情) 问题是我的网络浏览器和其他一些flash mp3播放器可以打开“”,而我的播放器却不能。但是,可以打开、播放、重播其他文件“” 我注意到我无法打开的文件有一些不同的标题(它没有内容长度标题)。但是,我再次尝试了其他一些没有内容长度头的文件,并且可以打开它 我不知道我错在哪里…:D帮助,并提前感谢!:) Susan听起来这显然是MP3编码的问题,
Susan听起来这显然是MP3编码的问题,而不是AS3代码的问题
.mp3
只是一个用于保存文件的包装器-有许多、无数、不同的方法来编码.mp3
文件中的实际内容
其中一些编码在Flash中可能是友好的,有些可能不是。您应该使用iTunes、Audacity、VLC媒体播放器、手刹或其他工具重新导出(或“压缩”)所有不工作的
.mp3
文件。我推荐AdobeMediaEncoder
好吧,这是可能的,但是,我的站点现在有超过80000个文件,我从其他站点加载了大约1500.000个文件,我无法控制这150万个文件。我正在与这些文件的持有者合作,但我怀疑他们是否愿意为我处理所有文件。。。此外,正如我所提到的,其他mp3播放器,如JWPlayer(已测试!),正在加载我所有来源的每个文件。有没有比URLRequest或to.load()更好的加载文件的方法?如果JW能做到,你、我、其他任何人都能做到,做到这一点的方法才是真正的问题……;)
import flash.events.MouseEvent;
import flash.media.Sound;
import flash.net.URLRequest;
import flash.media.SoundChannel;
// First run
if (songPlaying == undefined) {
var songPlaying = '0';
var songPause = '0';
var songLoadingCompleted = '1';
var prevSongURL:Array;
var currentSongURL:Array;
var nextSongURL:Array;
var soundFile:URLRequest;
var currentSong:Sound;
var channel:SoundChannel;
currentSongURL = ['','',''];
trace("Player defaults loaded.");
}
// Testing vars
nextSongURL = ['1','NEXT','http://www.balkanize.me/dll/dl5/Sasa_Kovacevic_Slucajno.mp3'];
prevSongURL = ['3','PREV','http://tm-alonso.perso.sfr.fr/Musique/NRJ%20Music%20Awards%202012/CD1/06%20-%20Pitbull%20feat.%20Chris%20Brown%20-%20International%20Love.mp3'];
//soundFile = new URLRequest(lastPlayedSongURL[2]);
//currentSong = new Sound();
//channel = new SoundChannel();
trace("Testing values loaded.");
//JS communication
//Get next next file
function getNextSong(lastPlayed:Array) {
//NOT FINISHED
trace("Loading next track");
return nextSongURL;
}
//Get previous next file
function getPrevSong(lastPlayed:Array){
//NOT FINISHED
trace("Loading prev track");
return prevSongURL;
}
//FUNCTIONS
function songLoadingProgress(evt:ProgressEvent):void{
var loadedPct:uint = Math.round(100 * (evt.bytesLoaded / evt.bytesTotal));
trace("The sound is " + loadedPct + "% loaded.");
}
function songLoadingComplete(evt:Event):void{
trace("The sound is completely loaded.");
songLoadingCompleted = '1';
}
function onIOError(evt:IOErrorEvent){
trace("The sound could not be loaded: " + evt.text);
}
// Player controls
function playSong(evt:MouseEvent):void {
if (songPlaying !== '1') {
info.text = "PLAY!";
if (currentSongURL[2] == '') {
currentSongURL = getNextSong(currentSongURL);
}
trace("Trying to play:" + currentSongURL[0] + " - " + currentSongURL[1] + " - " + currentSongURL[2]);
if (songLoadingCompleted !== '1') {
currentSong.close();
currentSong = new Sound();
}
songLoadingCompleted = '0';
soundFile = new URLRequest(currentSongURL[2]);
currentSong = new Sound();
channel = new SoundChannel();
currentSong.load(soundFile);
channel = currentSong.play(songPause);
currentSong.addEventListener(ProgressEvent.PROGRESS, songLoadingProgress);
currentSong.addEventListener(Event.COMPLETE, songLoadingComplete);
currentSong.addEventListener(IOErrorEvent.IO_ERROR, onIOError);
//channel.addEventListener(Event.SOUND_COMPLETE, onPlaybackComplete);
songPlaying = '1';
songPause = '0';
}
}
function stopSong(evt:MouseEvent):void {
if (songPlaying !== '0') {
trace('STOP!');
songPause = '0';
songPlaying = '0';
channel.stop();
return;
}
}
function playNext(evt:MouseEvent):void {
if (songPlaying !== '0') {
trace('STOP!');
songPlaying = '0';
channel.stop();
}
currentSongURL = getNextSong(currentSongURL);
playSong(null);
}
function playPrev(evt:MouseEvent):void {
if (songPlaying !== '0') {
trace('STOP!');
songPlaying = '0';
channel.stop();
}
currentSongURL = getPrevSong(currentSongURL);
playSong(null);
}
btnPrev.addEventListener(MouseEvent.CLICK,playPrev);
btnPlay.addEventListener(MouseEvent.CLICK,playSong);
// btnPause.addEventListener(MouseEvent.CLICK,pauseSong);
btnStop.addEventListener(MouseEvent.CLICK,stopSong);
btnNext.addEventListener(MouseEvent.CLICK,playNext);