Here is how to add a dynamic title to Subsonic:
We are going to edit playlist.jsp and videoPlayer.jsp.
First, we are going to edit playlist.jsp.
Add these variables at the beginning of the script section:
- Code: Select all
var playing = 0;
var finished = 1;
var playingTitle = null;
Add "top.document.title = "Subsonic";" to the end of the init() function.
Now replace the stateListener() function with this:
- Code: Select all
function stateListener(obj) { // IDLE, BUFFERING, PLAYING, PAUSED, COMPLETED
if (obj.newstate == "COMPLETED") {
playing = 0;
finished = 1;
onNext(repeatEnabled);
} else if (obj.newstate == "PLAYING") {
playing = 1;
finished = 0;
updateTitle(playingTitle);
} else if (obj.newstate == "PAUSED") {
playing = 0;
updateTitle("Paused - " + playingTitle);
} else if (obj.newstate == "IDLE") {
playing = 0;
updateTitle('Subsonic');
}
}
Now add the following to the end of the skip() function:
- Code: Select all
playingTitle = song.artist + ' - ' + song.title;
updateTitle(song.artist + ' - ' + song.title);
Finally, add this function:
- Code: Select all
function updateTitle(titleText) {
if (titleText) {
top.document.title = titleText;
} else if (playing == 0 && !finished && playingTitle && songs.length > 0) {
top.document.title = "Paused - " + playingTitle;
} else if (playing == 1 && songs.length > 0) {
top.document.title = playingTitle;
} else {
top.document.title = "Subsonic";
}
}
Now we are going to edit videoPlayer.jsp.
Add the variable "top.document.title = "Subsonic";" at the beginning of the script section.
Add "player.addModelListener("STATE", "stateListener");" right after the timeListener like so:
- Code: Select all
function playerReady(thePlayer) {
player = $("player1");
player.addModelListener("TIME", "timeListener");
player.addModelListener("STATE", "stateListener");
<c:if test="${not (model.trial and model.trialExpired)}">
play();
</c:if>
}
Now add this function:
- Code: Select all
function stateListener(obj) { // IDLE, BUFFERING, PLAYING, PAUSED, COMPLETED
if (obj.newstate == "PLAYING") {
paused = 0;
document.title = "${model.video.title}";
if (top.frames["playlist"]) {
top.playlist.updateTitle("${model.video.title}");
}
} else if (obj.newstate == "PAUSED") {
paused = 1;
document.title = "Paused - " + "${model.video.title}";
if (top.frames["playlist"]) {
top.playlist.updateTitle("Paused - " + "${model.video.title}");
}
} else if (obj.newstate == "BUFFERING") {
paused = 1;
document.title = "Buffering - " + "${model.video.title}";
if (top.frames["playlist"]) {
top.playlist.updateTitle("Buffering - " + "${model.video.title}");
}
} else if (obj.newstate == "COMPLETED") {
paused = 1;
if (top.frames["playlist"]) {
top.playlist.updateTitle();
}
}
}
Hope this helps!
