我使用的是JavaScript代码使用medialement.js的MediaElement加载视频播放器在音频标签
的配置如下加载链接MP3:
HTML
<a class="audio-player" href="some.mp3">This mp3 is cool</a>
的Javascript :
var audioDiv = document.getElementsByClassName("audio-player");
$(audioDiv).each(function(index) {
if ($(this).className != 'mediaplayer-processed') {
var playlist = $(this).attr('href');
playlist = playlist.replace("%20", " ");
sourceType = playlist.split('.').pop().toLowerCase();
if (sourceType == 'mp3') {
sourceType = 'mpeg';
}
audioTag = '<audio class="audio-player">'
audioTag = audioTag + '<source type="audio/' + sourceType + '" src="' + playlist + '" />';
audioTag = audioTag + '</audio>';
$(this).outerHTML=audioTag;
config_me = {
// enables Flash and Silverlight to resize to content size
enableAutosize: true,
// the order of controls you want on the control bar (and other plugins below)
features: ['playpause','volume'],
// Hide controls when playing and mouse is not over the video
alwaysShowControls: true,
};
// I need to set the video height and width because it is displayed as video
config_me.videoHeight = 30;
config_me.videoWidth = 60;
config_me.audioWidth = 60;
config_me.audioHeight = 30;
config_me.loop = false;
$(this).addClass('mediaplayer-processed').mediaelementplayer(config_me);
}
});
现在我期望/想要的是一个简约的音频播放器,但我得到是一个完整的视频播放器和mediaelement加载类“mejs-video”而不是“mejs-audio”。
我试着强制config_me中的类型,但它仍然作为视频加载。
我错过了什么吗?我使用的是mediaelement 2.15.2。
非常感谢您的详细回答!我现在完成了它的工作,最重要的是,我学到了更多关于JS的知识。 – mancuernita 2014-10-29 14:50:16