私はここで見つけるガイドに従ってのjQueryを使用して、カスタムHTML5オーディオプレーヤーを構築しました:次のようhttp://neutroncreations.com/blog/building-a-custom-html5-audio-player-with-jquery/複数のインスタンス
私のスクリプトは次のとおりです。
jQuery(document).ready(function() {
audio = jQuery('div#artificial-brothers audio').get(0);
loadingIndicator = jQuery('div#artificial-brothers #loading');
positionIndicator = jQuery('div#artificial-brothers #handle');
timeleft = jQuery('div#artificial-brothers #timeleft');
if ((audio.buffered != undefined) && (audio.buffered.length != 0)) {
jQuery(audio).bind('progress', function() {
var loaded = parseInt(((audio.buffered.end(0)/audio.duration) * 100), 10);
loadingIndicator.css({width: loaded + '%'});
});
} else {
loadingIndicator.remove();
}
jQuery(audio).bind('timeupdate', function() {
var rem = parseInt(audio.duration - audio.currentTime, 10),
pos = (audio.currentTime/audio.duration) * 100,
mins = Math.floor(rem/60,10),
secs = rem - mins*60;
timeleft.text('-' + mins + ':' + (secs < 10 ? '0' + secs : secs));
//if (!manualSeek) {
positionIndicator.css({width: pos + '%'});
// }
//if (!loaded) {
// loaded = true;
jQuery('div#artificial-brothers #gutter').slider({
value: 0,
step: 0.01,
orientation: "horizontal",
range: "min",
max: audio.duration,
animate: true,
slide: function() {
manualSeek = true;
},
stop:function(e,ui) {
manualSeek = false;
audio.currentTime = ui.value;
}
});
}).bind('play',function(){
jQuery('div#artificial-brothers #playtoggle').addClass('playing');
}).bind('pause ended', function() {
jQuery('div#artificial-brothers #playtoggle').removeClass('playing');
});
jQuery('div#artificial-brothers #playtoggle').click(function() {
if (audio.paused) { audio.play(); }
else { audio.pause(); }
});
jQuery('div#artificial-brothers #stoptoggle').click(function() {
if (audio.play) { audio.pause(); }
audio.currentTime = 0;
});
});
私の問題は、ということです私は同じページ上で前記のプレーヤーの複数のインスタンスを実行する必要があり、私はこれを達成するように見えません。スクリプトのコピー/貼り付けとid(人工兄弟)の変更を試みましたが、最後に書き込まれたスクリプトのみが実際に動作します。どのようにプレイヤーをページ上で複数回呼び出すかについてのアイデアは素晴らしいでしょう!
//カスパー
EDIT:@charlieftlによって与えられた情報によると、私のコードは次のようになります。
私はあなたが要素のIDを繰り返している疑いがあるjQueryのセレクターの使用によって判断jQuery(document).ready(function() {
jQuery('.player').each(function(){
var container = jQuery(this);
var audio = container.find('audio').get(0);
var loadingIndicator = container.find('.loading');
var positionIndicator = container.find('.handle');
var slider = container.find('.gutter');
var timeleft = container.find('.timeleft');
if ((audio.buffered != undefined) && (audio.buffered.length != 0)) {
jQuery(audio).bind('progress', function() {
var loaded = parseInt(((audio.buffered.end(0)/audio.duration) * 100), 10);
loadingIndicator.css({width: loaded + '%'});
});
} else {
loadingIndicator.remove();
}
jQuery(audio).bind('timeupdate', function() {
var rem = parseInt(audio.duration - audio.currentTime, 10),
pos = (audio.currentTime/audio.duration) * 100,
mins = Math.floor(rem/60,10),
secs = rem - mins*60;
timeleft.text('-' + mins + ':' + (secs < 10 ? '0' + secs : secs));
//if (!manualSeek) {
positionIndicator.css({width: pos + '%'});
// }
//if (!loaded) {
// loaded = true;
slider.slider({
value: 0,
step: 0.01,
orientation: "horizontal",
range: "min",
max: audio.duration,
animate: true,
slide: function() {
manualSeek = true;
},
stop:function(e,ui) {
manualSeek = false;
audio.currentTime = ui.value;
}
});
});
container.find('.playtoggle').click(function() {
if (audio.paused) { audio.play(); }
else { audio.pause(); }
});
container.find('.stoptoggle').click(function() {
if (audio.play) { audio.pause(); }
audio.currentTime = 0;
});
jQuery(audio).bind('play',function(){
container.find('.playtoggle').addClass('playing');
});
jQuery(audio).bind('pause ended', function() {
container.find('.playtoggle').removeClass('playing');
});
});
});
から絶縁インスタンスを保持することができますパターンを設定する例を十分にあります魅力のように働く!本当にありがとう!私は人々が見るだけの答えとして自分のコードを追加します。 –