我想在使用Durandal框架構建的Single Page App上使用jwplayer。這個想法是創建一個持久的音頻播放器,不受應用程序的導航影響。但是我一直無法在Durandal中加載jwplayer。在Durandal中加載jwplayer
我已經成功loaded jwplayer on a simple html file using Require.js。但是這種方法似乎不適用於Durandal(它也使用Require.js)。
這是我在shell.js代碼:
define(['jwplayer/jwplayer','durandal/plugins/router','durandal/app'], function (jwplayer,router,app) {
jwplayer.api('player').setup({
width: '320',
height: '40',
sources: [{
file: "rtmp://127.0.0.1:1935/vod/mp3:sample_1.mp3"
},{
file: "http://127.0.0.1:1935/vod/sample_1.mp3/playlist.m3u8"
}]
});
return {
router: router,
activate: function() {
...
}
};
});
而且shell.html裏面我有這樣的代碼:<div id="player">loading player...</div>
這是錯誤消息我得到:
Uncaught TypeError: Cannot read property 'id' of null jwplayer.js:37
看來,player
元素是面目全非在Durandal模塊內。什麼導致了這個問題?如何在Durandal模塊中添加jwplayer?
非常感謝你,這完美的作品。我還想知道DOM是否會引起這個問題,但我對Durandal的回調並不十分了解。 – 2013-04-05 03:34:29