기존 jplayer에 앨범 기능을 만들려고합니다.
이것은 작동하는 정적 코드입니다.
$(document).ready(function(){
new jPlayerPlaylist({
jPlayer: "#jquery_jplayer_1",
cssSelectorAncestor: "#jp_container_1"
}, [
{title:"01 - Standing (Still)", mp3:"music/Ongesorteerd/01 - Standing (Still).mp3"},
{title:"02 - Standing (Motion)", mp3:"music/Ongesorteerd/02 - Standing (Motion).mp3"}, // tracklist here
]);
$("#jplayer_inspector_1").jPlayerInspector({jPlayer:$("#jquery_jplayer_1")});
});
이제 변수를 사용하여 재생 목록을 채우고 싶습니다. 나는 JS라고 경고 할 수있는 유효한 변수를 만들 수 있었고 올바른지 확인했습니다.
내 질문은 내 (JS) 변수가 아닌 정적 재생 목록을 어떻게 바꿀 수 있습니까?
이것이 내가 시도한 것입니다.
function player(album, tracklist){
//alert(album+" ## "+tracklist);
var array = tracklist.split("+");
var track_count = array.length;
var tracks = "";
var i=0;
while(i < track_count)
{
tracks = tracks+'{title:"'+array[i]+'", mp3:"music/'+album+'/'+array[i]+'.mp3"},';
i++;
}
new jPlayerPlaylist({
jPlayer: "#jquery_jplayer_1",
cssSelectorAncestor: "#jp_container_1"
}, [
$(tracks) // this is the variable I'm talking about
]);
$("#jplayer_inspector_1").jPlayerInspector({jPlayer:$("#jquery_jplayer_1")});
}
다음과 같은 오류가 발생합니다.
오류 : 구문 오류, 인식 할 수없는 표현 : {title : "01-Standing (Still)", mp3 : "music / Ongesorteerd / 01-Standing (Still) .mp3"}, {title : "02-Standing (Motion)", mp3 : "music / Ongesorteerd / 02-Standing (Motion) .mp3"},
원본 코드에서 다음은 자바 스크립트 배열 리터럴을 나타냅니다.
[
{title:"01 - Standing (Still)", mp3:"music/Ongesorteerd/01 - Standing (Still).mp3"},
{title:"02 - Standing (Motion)", mp3:"music/Ongesorteerd/02 - Standing (Motion).mp3"}, // tracklist here
]
코드에서 배열 리터럴이 아닌 문자열을 작성합니다. 이런 식으로 시도
var tracks = [];
while(i < track_count)
{
tracks.push({
title: array[i],
mp3: "music/'+album+'/'+array[i]+'.mp3"
});
i++;
}
new jPlayerPlaylist({
jPlayer: "#jquery_jplayer_1",
cssSelectorAncestor: "#jp_container_1"
}, tracks );
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다