【发布时间】:2012-02-12 12:18:27
【问题描述】:
我正在尝试使用 mediaelement.js 设置播放器。 我正在实现自己的自定义播放列表 - 我希望页面上只有一个播放器,并且在单击播放列表中的不同标题时,它必须自动更改播放器的来源。
我已经用相当简单的代码实现了这一点。
这里是初始化:
var player = new MediaElementPlayer("#audioplayer",
{
//if the <video width> is not specified, this is the default
defaultVideoWidth: 480,
// if the <video height> is not specified, this is the default
defaultVideoHeight: 270,
// if set, overrides <video width>
videoWidth: -1,
// if set, overrides <video height>
videoHeight: -1,
// width of audio player
audioWidth: 960,
// height of audio player
audioHeight: 30,
// initial volume when the player starts
startVolume: 0.8,
// useful for <audio> player loops
loop: false,
// 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','progress','current','duration','tracks','volume','fullscreen'],
// automatically selects a <track> element
startLanguage: '',
// a list of languages to auto-translate via Google
translations: [],
// a dropdownlist of automatic translations
translationSelector: false,
// key for tranlsations
googleApiKey: '' }
);
这是在单击播放列表中的元素时更改 src 的代码。
document.getElementById('audioplayer').src = url;
if(url.search('youtube')!=-1 || url.search('youtu.be')!=-1)
{
document.getElementById('audioplayer').pluginType="youtube";
$('#audioplayer').attr("type","video/youtube");
}
else
{
document.getElementById('audioplayer').pluginType="native";
$('#audioplayer').attr("type","audio/mp3");
}
player.load();
player.play();
问题是播放器无法同时播放视频和音频源。我尝试更改所有参数,包括 src、pluginType 等。它要么只播放音频文件,要么播放视频文件。
谁能帮我解决这个问题?我猜它与初始化有关 - 如 MediaElement、AudioElement 或 VideoElement 等。
提前致谢。
【问题讨论】:
标签: mediaelement.js