请帮助解决这个问题,我只是尝试使用HTML5媒体播放器,直到现在我尝试从源文件夹中拉出音乐并且在此处显示此错误时,它一直平稳而稳定安慰。我正在使用UCBrowser。
var b = document.documentElement;
var tracks;
b.setAttribute('data-useragent', navigator.userAgent);
b.setAttribute('data-platform', navigator.platform);
// HTML5 audio player + playlist controls...
// Inspiration: http://jonhall.info/how_to/create_a_playlist_for_html5_audio
// Mythium Archive: https://archive.org/details/mythium/
$(document).ready(function(){
$.ajax({
type: "get",
url: "{!! URL::to('playSongs') !!}",
success: function(data){
tracks = data;
actionAudio();
}
});
function actionAudio(){
jQuery(function ($) {
var canvas, ctx, grd, source, context, analyser, fbc_array, bars, bar_x, bar_width, bar_height;
var supportsAudio = !!document.createElement('audio').canPlayType;
if (supportsAudio) {
var index = 0,
playing = false,
// mediaPath = '//archive.org/download/mythium/',
mediaPath = '/album/songs/',
extension = '',
trackCount = tracks.length,
npAction = $('#npAction'),
npTitle = $('#npTitle'),
audio = $('#audio1').bind('play', function () {
playing = true;
npAction.text('Now Playing...');
}).bind('pause', function () {
playing = false;
npAction.text('Paused...');
}).bind('ended', function () {
npAction.text('Paused...');
if ((index + 1) < trackCount) {
index++;
loadTrack(index);
audio.play();
} else {
audio.pause();
index = 0;
loadTrack(index);
}
}).get(0),
btnPrev = $('#btnPrev').click(function () {
if ((index - 1) > -1) {
index--;
loadTrack(index);
if (playing) {
audio.play();
}
} else {
audio.pause();
index = 0;
loadTrack(index);
}
}),
btnNext = $('#btnNext').click(function () {
if ((index + 1) < trackCount) {
index++;
loadTrack(index);
if (playing) {
audio.play();
}
} else {
audio.pause();
index = 0;
loadTrack(index);
}
}),
li = $('#plList li').click(function () {
var id = parseInt($(this).index());
if (id !== index) {
playTrack(id);
}
}),
loadTrack = function (id) {
$('.plSel').removeClass('plSel');
$('#plList li:eq(' + id + ')').addClass('plSel');
npTitle.text(tracks[id].name);
index = id;
audio.src = mediaPath + tracks[id].file; // + extension;
},
playTrack = function (id) {
loadTrack(id);
audio.play();
};
//extension = audio.canPlayType('audio/mpeg') ? '.mp3' : audio.canPlayType('audio/ogg') ? '.ogg' : '';
loadTrack(index);
window.addEventListener("load", initMP3Player(audio), false);
audio.crossOrigin = "anonymous";
}
});
}
});
控制台出错:
GET http://localhost:8000/album/songs/undefined
我不知道为什么会在网址上附加未定义的原因。普通网址应为http://localhost:8000/album/songs/song_name.mp3