I created chromecast app for casting specific image from web to screen but what I need now is add possibility to choose photo from my pc to cast. I tried with Javascript class FileReader using function readAsDataUrl(). It works if i want to display image on page but it says Media error when trying to cast it.Maybe becouse of format?Anyone knows hot to fix it or maybe different aproach for this problem that works?
code:
$(function () {
$(":file").change(function () {
if (this.files && this.files[0]) {
var reader = new FileReader();
reader.onload = imageIsLoaded;
reader.readAsDataURL(this.files[0]);
}
});
});
function imageIsLoaded(e) {
url= e.target.result;
$('#myImg').attr('src', e.target.result);}
....
function loadMedia(){
var mediaInfo=new chrome.cast.media.MediaInfo(url,type);
mediaInfo.metadata=new chrome.cast.media.PhotoMediaMetadata();
mediaInfo.metadata.metadataType=chrome.cast.media.MetadataType.PHOTO;
mediaInfo.contentType=type;
var request=new chrome.cast.media.LoadRequest(mediaInfo);
session.loadMedia(request,onMediaDiscovered.bind(this,"loadMedia"),onMediaError.bind(this));
}