我正在使用Google Cast SDK做一个发件人应用程序,但是当我尝试将媒体播放到智能电视时,我收到一个错误消息:未选择媒体。一切正常,但我不能播放媒体
我想使用Google Cast SDK将发件人应用中的视频播放到我的智能电视上,但出现错误
//侦听器
private void setupCastListener(){
mSessionManagerListener = new SessionManagerListener<CastSession>() {
//Si hay errores poner en cada uno un toast el porque
@Override
public void onSessionEnded(CastSession castSession, int i) {
onAplicationDisconnected();
}
@Override
public void onSessionResumed(CastSession castSession, boolean b) {
onAplicationConnected(castSession);
}
@Override
public void onSessionResumeFailed(CastSession castSession, int i) {
onAplicationDisconnected();
}
@Override
public void onSessionStarted(CastSession castSession, String s) {
onAplicationConnected(castSession);
}
@Override
public void onSessionStartFailed(CastSession castSession, int i) {
onAplicationDisconnected();
}
@Override
public void onSessionStarting(CastSession castSession) {
Toast.makeText(DetailsActivity.this, "Iniciando conexion", Toast.LENGTH_SHORT).show();
}
@Override
public void onSessionEnding(CastSession castSession) {
Toast.makeText(DetailsActivity.this, "Sesion finalizada", Toast.LENGTH_SHORT).show();
}
@Override
public void onSessionResuming(CastSession castSession, String s) {
Toast.makeText(DetailsActivity.this, "Sesion retomadda", Toast.LENGTH_SHORT).show();
}
@Override
public void onSessionSuspended(CastSession castSession, int i) {
}
private void onAplicationConnected(CastSession castSession){
mcastSession = castSession;
if(!util.getUrl().equals("")){
//VideoPlayer
Toast.makeText(DetailsActivity.this, "Url ha mostrar " + util.getUrl(), Toast.LENGTH_SHORT).show();
loadRemoteMedia();
Toast.makeText(DetailsActivity.this, "Se ha conectado correctamente", Toast.LENGTH_SHORT).show();
}else{
Toast.makeText(DetailsActivity.this, "La url no pudo ser leida", Toast.LENGTH_LONG).show();
}
}
private void onAplicationDisconnected(){
Toast.makeText(DetailsActivity.this, "El dispositivo se ha desconectado", Toast.LENGTH_SHORT).show();
}
};
}
private void loadRemoteMedia() {
//Cargar datos
try {
if (mcastSession == null){
Toast.makeText(this, "No hay ningun dispositivo conectado", Toast.LENGTH_SHORT).show();
return;
}
RemoteMediaClient remoteMediaClient = mcastSession.getRemoteMediaClient();
if (remoteMediaClient == null){
Toast.makeText(this, "No hay MediaClient ", Toast.LENGTH_SHORT).show();
return;
}
remoteMediaClient.load(buildMediaInfo(),
new MediaLoadOptions.Builder()
.setAutoplay(true)
.setPlayPosition(0).build());
}catch (Exception e){
Toast.makeText(this, "Load Remote Media is configured bad", Toast.LENGTH_SHORT).show();
}
}
private MediaInfo buildMediaInfo() {
MediaMetadata movieMetadata = new MediaMetadata(MediaMetadata.MEDIA_TYPE_MOVIE);
movieMetadata.putString(MediaMetadata.KEY_TITLE,"Dragon Ball");
return new MediaInfo.Builder(util.getUrl())
.setStreamType(MediaInfo.STREAM_TYPE_BUFFERED)
.setContentType("videos/mp4")
.setMetadata(movieMetadata)
.build();
}
我希望在智能电视上播放媒体,但出现下一个错误:未选择媒体