I'd thought i'd share my experience with enabling subtitles for Subsonic.
I've been using Subsonic for a long time and i love it. The only problem for me has been the lack of supported subtitles. Never really bothered to look for a solution cause i was sure it was gonna get implemented anyway and to be honest i dont really mind watching without subtitles.
In any case, i was watching a movie with a lot of foreign languages so i thought i'd look for a subtitle patch. I found this thread and tried out the patch and it works great, except for the going out of sync when skipping ahead part. I did a little tweaking and got it working and i thought i'd share it here since this is where if found the initial tweak.
TLDR: look at the bottom for the download link.Ok so, the problem was the subtitle going out of sync when skipping ahead. Easy fix, i thought. Just have the subtitle offset when skipping ahead. Great idea, except that JWPlayer Captions plugin doesn't support offsetting the subtitle. That's fine though, since its open source.
First thing i did was was grab the source from here:
http://developer.longtailvideo.com/trac ... s/captionsIt's very easy to compile. All you have to do is go into the 'build' folder and run the .bat file (for windows). Obviously you need Flex SDK for it to work though but you can get that easily from adobes site.
Now you need to make the JWplayer in Subsonic load your plugin. Usually JWplayer loads plugins directly from their site (
http://www.longtailvideo.com). That's an easy fix.
Open up subsonic.war in winrar or some other tool to open compressed libraries. You'll find the file in your subsonic installation. Once open navigate to WEB-INF/jsp/videoPlayer.jsp and open that file in a text editor.
Follow standardnoise and Miles directions above and then continue here. I'm goin to assume you have already added their code.
Find the variable 'flashvars' in the init() function and edit this line.
- Code: Select all
plugins:"captions-2",
into this:
- Code: Select all
plugins:"./flash/captions.swf",
It should look something like this.
- Code: Select all
var flashvars = {
id:"player1",
skin:"<c:url value="/flash/whotube.zip"/>",
// plugins:"metaviewer-1",
plugins:"./flash/captions.swf",
'captions.file':srtPath,
screencolor:"000000",
controlbar:"over",
autostart:"false",
bufferlength:3,
backcolor:"<spring:theme code="backgroundColor"/>",
frontcolor:"<spring:theme code="textColor"/>",
provider:"video"
};
So far its very similar to the above solution. Now it's where i add a few things.
In the same subsonic.war file you opened videoPlayer.jsp in, go back all the way to the initial folder. Go into the folder named 'flash'. In here drag and drop(if you used winrar) the file we compiled before. If you didnt change the build script it should be named captions.swf and be located where you saved the source code for the captions plugin.
Now you should have two files in the flash directory.
- Code: Select all
captions.swf
jw-player-5.6.swf
Save the war file and close it for now. Restart subsonic and go watch a movie. If you get no errors it means that JWplayer correctly reads the local copy of the captions plugin. Now we can modify it to our needs.
Go back into the uncomliled source code for the captions plugin and navigate to this file: src\as\com\longtailvideo\plugins\captions\Captions.as
Open it up in your favorite text editor (notepad++ is lovely). Alright, now navigate to line 30ish. You're looking for this variable:
- Code: Select all
private var _config:Object = {
back: false,
label: undefined,
file: undefined,
state: true
};
Change it so it looks like this:
- Code: Select all
private var _config:Object = {
back: false,
label: undefined,
file: undefined,
state: true,
offset: 0
};
Find this line on row 169:
- Code: Select all
_renderer = new Renderer(_defaults,_config.back);
Edit it into this:
- Code: Select all
_renderer = new Renderer(_defaults,_config.back,_config.offset);
When you're done with that go ahead and save the file and close it. Now open up Renderer.as in the same folder. Add this line:
- Code: Select all
private var _offset:Number;
After:
- Code: Select all
private var _style:Object;
Find the constructor:
- Code: Select all
/** Constructor; solely inits the captions file loader. **/
public function Renderer(style:Object,outline:Boolean) {
Modify it into:
- Code: Select all
/** Constructor; solely inits the captions file loader. **/
public function Renderer(style:Object,outline:Boolean,offset:Number) {
Now on the line right after add this:
- Code: Select all
_offset = offset;
Then find this snippet of code within the _selectCaption() function:
- Code: Select all
for (var i:Number=0; i<_captions.length; i++) {
if (_captions[i]['begin'] <= _position &&
(i == _captions.length-1 || _captions[i+1]['begin'] >= _position)) {
found = i;
break;
}
}
Modify it into:
- Code: Select all
for (var i:Number=0; i<_captions.length; i++) {
if (_captions[i]['begin'] <= _position+_offset &&
(i == _captions.length-1 || _captions[i+1]['begin'] >= _position+_offset)) {
found = i;
break;
}
}
Go ahead and save that file too. Now you can go ahead and recompile the caption plugin again. Go back into the subsonic.war file and save it into the /flash/ folder. Overwriting the old one.
Now we're almost done. We just need to make a few more modifications to videoPlayer.jsp. Go ahead and open it again. Located in the subsonic.war at WEB-INF/jsp/videoPlayer.jsp.
This is getting quite lengty so ill just add the functions that you need to overwrite.
Replace entire init() with this:
- Code: Select all
function init() {
var flashvars = {
id:"player1",
skin:"<c:url value="/flash/whotube.zip"/>",
// plugins:"metaviewer-1",
screencolor:"000000",
plugins:"./flash/captions.swf",
'captions.file':srtPath,
'captions.offset':timeOffset,
controlbar:"over",
autostart:"false",
bufferlength:3,
backcolor:"<spring:theme code="backgroundColor"/>",
frontcolor:"<spring:theme code="textColor"/>",
provider:"video"
};
var params = {
allowfullscreen:"true",
allowscriptaccess:"always"
};
var attributes = {
id:"player1",
name:"player1"
};
var width = "${model.popout ? '100%' : '600'}";
var height = "${model.popout ? '85%' : '360'}";
swfobject.embedSWF("<c:url value="/flash/jw-player-5.6.swf"/>", "placeholder1", width, height, "9.0.0", false, flashvars, params, attributes);
}
Replace entire changeTimeOffset() with this:
- Code: Select all
function changeTimeOffset() {
timeOffset = $("timeOffset").getValue();
player.remove();
var wrapperelement = document.getElementById("wrapper");
var placeholder = document.createElement('div');
placeholder.setAttribute('id','placeholder1');
wrapperelement.appendChild(placeholder);
init();
}
Save it. Update your war. Restart Subsonic and dont forget to clear your cache. And you're done.
You might wonder why i had to remove the entire player and then add it again. Believe me i was wondering the same. But apparently you can only set flashvars when you create the player. Oh well. Now it works.
In any case, if you thought that the above is to tedious/hard/boring/whatever i have the compiled subsonic.war for you right here. It's for 4.7 beta 2.
http://www.filedropper.com/subsonicUsing this method you could easily modify it to work when changing bitrates as well. You could even create a list of subtitles to switch between if you wanted. But i'll leave that for someone with more time than me. If no one wants to see how far this method can go i might pick it up again when i have more time.
Good Luck!