问题
I use jwplayer.version = '5.10.2295' and browser chrome 25.
My code:
jwplayer('container').setup({
file: 'path...',
width: '300px',
height: '100px',
autostart: true,
modes: [
{ type: 'html5' },
{ type: 'flash', src: 'path...' }
]
});
When page is loaded my resource (mp4 video file) starts to show correctrly - it is ok. But there is no reaction on simple jwplayer JS API methods, suche as jwplayer().stop(), for example. And some controls are not available (play, top, seek), but 'to full screen mode' button works as well as volume button.
And the most interesting is that js api and control buttons available for a few seconds after video start to play (if browser cache is cleared), and then no response for interaction. But some method works all the time correctly (jwplayer().setFullscreen() for example).
p.s. I saw related question but the answer is not deep anough for me.
回答1:
I found solution.
My video file have no specified extension in path (i have 'path/to/file' instead of 'path/to/file.mp4') and that fact brokes somethin in the depths of jwPlayer. We need to specify type of file we operate with:
jwplayer('container').setup({
file: 'path/to/file-with-no-extension',
width: '300px',
height: '100px',
autostart: true,
type: 'video', //helps jwplayer to determine how to handle our resource with no extension
modes: [
{ type: 'html5' },
{ type: 'flash', src: 'path...' }
]
});
That's solution.
回答2:
Download jwplayer6 from http://www.longtailvideo.com/jw-player/download/
Put these files to the particular directory:-
- app/assets/jwplayer/jwplayer.flash.swf
- vendor/assets/javascripts/jwplayer.js
- vendor/assets/javascripts/jwplayer.html5.js
Then add these line in application.js
//= require jwplayer
//= require jwplayer.html5
On the page where you are playing video, add these lines
<script type="text/javascript">jwplayer.key="YOUR_JWPLAYER_KEY";</script>
<div id="video">Loading the player ...</div>
<script type="text/javascript">
jwplayer("video").setup({
flashplayer: "<%=asset_path('jwplayer.flash.swf')%>",
file: "<%= file_path %>",
height: 360,
width: 640,
analytics: {
enabled: false,
cookies: false
}
});
http://account.longtailvideo.com/#/home from where you can get your free self hosted key in signing up from Get Your License Key portion.
来源:https://stackoverflow.com/questions/13800386/jw-player-javascript-api-not-working