0

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));
    }
asd
  • 1
  • 1

1 Answers1

1

In order for chromecast to be able to fetch your image, you need to have a web server to serve the image. If it is not in the cloud, then your sender (web or phone) needs to embed a web server and then communicate the URL of the image, as served by the web server, to chromecast.

Ali Naddaf
  • 16,951
  • 2
  • 21
  • 28