mirror of
https://github.com/KevinMidboe/zoff.git
synced 2025-10-29 18:00:23 +00:00
Now working with loadMedia on chromecast
This commit is contained in:
@@ -435,11 +435,51 @@ function setup_no_connection_listener(){
|
||||
});
|
||||
}
|
||||
|
||||
function loadChromecastVideo() {
|
||||
castSession = cast.framework.CastContext.getInstance().getCurrentSession();
|
||||
var _seekTo;
|
||||
try{
|
||||
if(videoSource == "youtube") {
|
||||
_seekTo = Player.player.getCurrentTime();
|
||||
} else if(videoSource == "soundcloud") {
|
||||
_seekTo = Player.soundcloud_player.currentTime() / 1000;
|
||||
}
|
||||
} catch(event){
|
||||
_seekTo = seekTo;
|
||||
}
|
||||
var mediaInfo = new chrome.cast.media.MediaInfo(video_id, videoSource);
|
||||
var image = {url:'https://img.youtube.com/vi/'+video_id+'/mqdefault.jpg', heigth: 180, width: 320};
|
||||
if(Player.np.thumbnail) image.url = Player.np.thumbnail;
|
||||
mediaInfo.metadata = new chrome.cast.media.GenericMediaMetadata();
|
||||
mediaInfo.metadata.title = Player.np.title;
|
||||
mediaInfo.metadata.image = image;
|
||||
mediaInfo.metadata.images = [image];
|
||||
var request = new chrome.cast.media.LoadRequest(mediaInfo);
|
||||
request.media.customData = {
|
||||
start: Player.np.start,
|
||||
end: Player.np.end,
|
||||
seekTo: _seekTo,
|
||||
channel: chan.toLowerCase(),
|
||||
thumbnail: Player.np.thumbnail != undefined ? Player.np.thumbnail : 'https://img.youtube.com/vi/'+video_id+'/mqdefault.jpg',
|
||||
};
|
||||
castSession.loadMedia(request).then(function() {
|
||||
var _player = new cast.framework.RemotePlayer();
|
||||
var _controller = new cast.framework.RemotePlayerController(_player);
|
||||
window._controller = _controller;
|
||||
window._player = _player;
|
||||
|
||||
},
|
||||
function(errorCode) {
|
||||
console.log('Error code: ' + errorCode);
|
||||
});
|
||||
}
|
||||
|
||||
function updateChromecastMetadata() {
|
||||
if(!chromecastAvailable) return;
|
||||
var image = 'https://img.youtube.com/vi/'+video_id+'/mqdefault.jpg';
|
||||
if(Player.np.thumbnail) image = Player.np.thumbnail;
|
||||
var image = {url:'https://img.youtube.com/vi/'+video_id+'/mqdefault.jpg', heigth: 180, width: 320};
|
||||
if(Player.np.thumbnail) image.url = Player.np.thumbnail;
|
||||
chrome.cast.media.GenericMediaMetadata({metadataType: 0, title:Player.np.title, image: image, images: [image]});
|
||||
return new chrome.cast.media.GenericMediaMetadata({metadataType: 0, title:Player.np.title, image: image, images: [image]});
|
||||
}
|
||||
|
||||
function setup_now_playing_listener(){
|
||||
|
||||
@@ -287,22 +287,14 @@ initializeCastApi = function() {
|
||||
chromecastAvailable = true;
|
||||
paused = false;
|
||||
mobile_beginning = false;
|
||||
var _seekTo;
|
||||
try{
|
||||
if(videoSource == "youtube") {
|
||||
_seekTo = Player.player.getCurrentTime();
|
||||
} else if(videoSource == "soundcloud") {
|
||||
_seekTo = Player.soundcloud_player.currentTime() / 1000;
|
||||
}
|
||||
} catch(event){
|
||||
_seekTo = seekTo;
|
||||
}
|
||||
castSession.sendMessage("urn:x-cast:zoff.me", {type: "loadVideo", start: Player.np.start, end: Player.np.end, videoId: video_id, seekTo: _seekTo, channel: chan.toLowerCase(), source: videoSource, thumbnail: Player.np.thumbnail})
|
||||
castSession.sendMessage("urn:x-cast:zoff.me", {type: "nextVideo", videoId: full_playlist[0].id, title: full_playlist[0].title, source: full_playlist[0].source, thumbnail: full_playlist[0].thumbnail})
|
||||
|
||||
//if(Helper.mobilecheck()) {
|
||||
//console.log("request here", request);
|
||||
//castSession.sendMessage("urn:x-cast:zoff.me", {type: "loadVideo", start: Player.np.start, end: Player.np.end, videoId: video_id, seekTo: _seekTo, channel: chan.toLowerCase(), source: videoSource, thumbnail: Player.np.thumbnail})
|
||||
castSession.sendMessage("urn:x-cast:zoff.me", {type: "nextVideo", videoId: full_playlist[0].id, title: full_playlist[0].title, source: full_playlist[0].source, thumbnail: full_playlist[0].thumbnail})
|
||||
loadChromecastVideo();
|
||||
if(window.location.hostname.indexOf("zoff.me") > -1 && !offline && window.location.hostname.indexOf("localhost") == -1) {
|
||||
socket.emit("get_id");
|
||||
//}
|
||||
}
|
||||
hide_native(1);
|
||||
if(Helper.mobilecheck()) {
|
||||
Player.playVideo();
|
||||
@@ -320,16 +312,12 @@ initializeCastApi = function() {
|
||||
chromecastAvailable = true;
|
||||
paused = false;
|
||||
mobile_beginning = false;
|
||||
var _seekTo;
|
||||
try{
|
||||
_seekTo = Player.player.getCurrentTime();
|
||||
} catch(event){
|
||||
_seekTo = seekTo;
|
||||
}
|
||||
//if(Helper.mobilecheck()) {
|
||||
|
||||
if(window.location.hostname.indexOf("zoff.me") > -1 && !offline && window.location.hostname.indexOf("localhost") == -1) {
|
||||
socket.emit("get_id");
|
||||
//}
|
||||
castSession.sendMessage("urn:x-cast:zoff.me", {type: "loadVideo", start: Player.np.start, end: Player.np.end, videoId: video_id, seekTo: _seekTo, channel: chan.toLowerCase(), source: videoSource, thumbnail: Player.np.thumbnail})
|
||||
}
|
||||
loadChromecastVideo();
|
||||
//castSession.sendMessage("urn:x-cast:zoff.me", {type: "loadVideo", start: Player.np.start, end: Player.np.end, videoId: video_id, seekTo: _seekTo, channel: chan.toLowerCase(), source: videoSource, thumbnail: Player.np.thumbnail})
|
||||
castSession.sendMessage("urn:x-cast:zoff.me", {type: "nextVideo", videoId: full_playlist[0].id, title: full_playlist[0].title, source: full_playlist[0].source, thumbnail: full_playlist[0].thumbnail})
|
||||
hide_native(1);
|
||||
Helper.css("#channel-load", "display", "none");
|
||||
|
||||
@@ -355,7 +355,8 @@ var Player = {
|
||||
Suggestions.fetchYoutubeSuggests(id);
|
||||
}
|
||||
if(chromecastAvailable){
|
||||
castSession.sendMessage("urn:x-cast:zoff.me", {start: s, end: e, type: "loadVideo", videoId: id, channel: chan.toLowerCase(), source: videoSource, thumbnail: Player.np.thumbnail});
|
||||
//castSession.sendMessage("urn:x-cast:zoff.me", {start: s, end: e, type: "loadVideo", videoId: id, channel: chan.toLowerCase(), source: videoSource, thumbnail: Player.np.thumbnail, title: Player.np.title});
|
||||
loadChromecastVideo();
|
||||
chrome.cast.media.GenericMediaMetadata({metadataType: 0, title:song_title, image: 'https://img.youtube.com/vi/'+id+'/mqdefault.jpg', images: ['https://img.youtube.com/vi/'+id+'/mqdefault.jpg']});
|
||||
chrome.cast.Image('https://img.youtube.com/vi/'+id+'/mqdefault.jpg');
|
||||
} else {
|
||||
@@ -487,7 +488,8 @@ var Player = {
|
||||
Player.getTitle(song_title, viewers);
|
||||
//Player.setBGimage(video_id);
|
||||
if(chromecastAvailable){
|
||||
castSession.sendMessage("urn:x-cast:zoff.me", {type: "loadVideo", videoId: video_id, channel: chan.toLowerCase(), start: start, end:end, source: videoSource});
|
||||
loadChromecastVideo();
|
||||
//castSession.sendMessage("urn:x-cast:zoff.me", {type: "loadVideo", videoId: video_id, channel: chan.toLowerCase(), start: start, end:end, source: videoSource});
|
||||
chrome.cast.media.GenericMediaMetadata({metadataType: 0, title:song_title, image: 'https://img.youtube.com/vi/'+video_id+'/mqdefault.jpg', images: ['https://img.youtube.com/vi/'+video_id+'/mqdefault.jpg']});
|
||||
chrome.cast.Image('https://img.youtube.com/vi/'+video_id+'/mqdefault.jpg');
|
||||
} else {
|
||||
@@ -523,7 +525,8 @@ var Player = {
|
||||
//Player.setBGimage(video_id);
|
||||
|
||||
if(chromecastAvailable){
|
||||
castSession.sendMessage("urn:x-cast:zoff.me", {type: "loadVideo", videoId: video_id, channel: chan.toLowerCase(), start: start, end: end, source: videoSource});
|
||||
loadChromecastVideo();
|
||||
//castSession.sendMessage("urn:x-cast:zoff.me", {type: "loadVideo", videoId: video_id, channel: chan.toLowerCase(), start: start, end: end, source: videoSource});
|
||||
chrome.cast.media.GenericMediaMetadata({metadataType: 0, title:song_title, image: 'https://img.youtube.com/vi/'+video_id+'/mqdefault.jpg', images: ['https://img.youtube.com/vi/'+video_id+'/mqdefault.jpg']});
|
||||
chrome.cast.Image('https://img.youtube.com/vi/'+video_id+'/mqdefault.jpg');
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user