这是来自Codepen的玩家。 https://codepen.io/markhillard/pen/Hjcwu
如何更改它以通过URL播放我自己的.mp3文件
例如,如果我的mp3文件网址为www.website.com/audiofile.mp3
我尝试将mediaPath更改为“ https://www.website.com”,并将“ file”:“ JLS_ATI”更改为“ file”:“ audiofile.mp”
但是没用
jQuery(function ($) {
'use strict'
var supportsAudio = !!document.createElement('audio').canPlayType;
if (supportsAudio) {
// initialize plyr
var player = new Plyr('#audio1', {
controls: [
'restart',
'play',
'progress',
'current-time',
'duration',
'mute',
'volume',
'download'
]
});
// initialize playlist and controls
var index = 0,
playing = false,
mediaPath = 'https://archive.org/download/mythium/',
extension = '',
tracks = [{
"track": 1,
"name": "All This Is - Joe L.'s Studio",
"duration": "2:46",
"file": "JLS_ATI"
}, {
"track": 2,
"name": "The Forsaken - Broadwing Studio (Final Mix)",
"duration": "8:30",
"file": "BS_TF"
}],
buildPlaylist = $.each(tracks, function(key, value) {
var trackNumber = value.track,
trackName = value.name,
trackDuration = value.duration;
if (trackNumber.toString().length === 1) {
trackNumber = '0' + trackNumber;
}
$('#plList').append('<li> \
<div class="plItem"> \
<span class="plNum">' + trackNumber + '.</span> \
<span class="plTitle">' + trackName + '</span> \
<span class="plLength">' + trackDuration + '</span> \
</div> \
</li>');
}),
trackCount = tracks.length,
npAction = $('#npAction'),
npTitle = $('#npTitle'),
audio = $('#audio1').on('play', function () {
playing = true;
npAction.text('Now Playing...');
}).on('pause', function () {
playing = false;
npAction.text('Paused...');
}).on('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').on('click', function () {
if ((index - 1) > -1) {
index--;
loadTrack(index);
if (playing) {
audio.play();
}
} else {
audio.pause();
index = 0;
loadTrack(index);
}
}),
btnNext = $('#btnNext').on('click', function () {
if ((index + 1) < trackCount) {
index++;
loadTrack(index);
if (playing) {
audio.play();
}
} else {
audio.pause();
index = 0;
loadTrack(index);
}
}),
li = $('#plList li').on('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;
updateDownload(id, audio.src);
},
updateDownload = function (id, source) {
player.on('loadedmetadata', function () {
$('a[data-plyr="download"]').attr('href', source);
});
},
playTrack = function (id) {
loadTrack(id);
audio.play();
};
extension = audio.canPlayType('audio/mpeg') ? '.mp3' : audio.canPlayType('audio/ogg') ? '.ogg' : '';
loadTrack(index);
} else {
// no audio support
$('.column').addClass('hidden');
var noSupport = $('#audio1').text();
$('.container').append('<p class="no-support">' + noSupport + '</p>');
}
});