Unable to cast youtube video URL from my Android application through Chromecast whereas I successfully played other video content from my server.
Here is the code:
private void startVideo() {
MediaMetadata mediaMetadata = new MediaMetadata( MediaMetadata.MEDIA_TYPE_MOVIE );
mediaMetadata.putString( MediaMetadata.KEY_TITLE, getString( R.string.video_title ) );
MediaInfo mediaInfo = new MediaInfo.Builder(
"http://www.youtube.com/watch?v=Zy0cCn7F7mw")
.setContentType( video/mp4 )
.setStreamType( MediaInfo.STREAM_TYPE_BUFFERED )
.setMetadata( mediaMetadata )
.build();
try {
mRemoteMediaPlayer.load( mApiClient, mediaInfo, true )
.setResultCallback( new ResultCallback<RemoteMediaPlayer.MediaChannelResult>() {
@Override
public void onResult( RemoteMediaPlayer.MediaChannelResult mediaChannelResult ) {
if( mediaChannelResult.getStatus().isSuccess() ) {
mVideoIsLoaded = true;
mButton.setText( getString( R.string.pause_video ) );
}
}
} );
} catch( Exception e ) {
}
}
I tried the MIME type with "video/webM" but not worked. Please help.
You're trying to cast an HTML web page that has the YouTube player on it rather than an actual video file itself, which won't work ... the content of the MediaInfo has to be the direct URL to the video stream.
What's more, you won't be able to get that for a YouTube video; all YouTube videos must be played via the YouTube player (on desktop or mobile).