Java Code Examples for com.google.android.gms.cast.MediaMetadata#MEDIA_TYPE_MOVIE

The following examples show how to use com.google.android.gms.cast.MediaMetadata#MEDIA_TYPE_MOVIE . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MainActivity.java    From AndroidDemoProjects with Apache License 2.0 6 votes vote down vote up
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( getString( R.string.video_url ) )
            .setContentType( getString( R.string.content_type_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 ) {
    }
}
 
Example 2
Source File: CastUtils.java    From UTubeTV with The Unlicense 6 votes vote down vote up
/**
 * Builds and returns a {@link MediaInfo} that was wrapped in a {@link Bundle} by
 */
public static MediaInfo toMediaInfo(Bundle wrapper) {
  if (null == wrapper) {
    return null;
  }

  MediaMetadata metaData = new MediaMetadata(MediaMetadata.MEDIA_TYPE_MOVIE);

  metaData.putString(MediaMetadata.KEY_SUBTITLE, wrapper.getString(MediaMetadata.KEY_SUBTITLE));
  metaData.putString(MediaMetadata.KEY_TITLE, wrapper.getString(MediaMetadata.KEY_TITLE));
  metaData.putString(MediaMetadata.KEY_STUDIO, wrapper.getString(MediaMetadata.KEY_STUDIO));
  ArrayList<String> images = wrapper.getStringArrayList(KEY_IMAGES);
  if (null != images && !images.isEmpty()) {
    for (String url : images) {
      Uri uri = Uri.parse(url);
      metaData.addImage(new WebImage(uri));
    }
  }
  return new MediaInfo.Builder(wrapper.getString(KEY_URL)).setStreamType(wrapper.getInt(KEY_STREAM_TYPE))
      .setContentType(wrapper.getString(KEY_CONTENT_TYPE))
      .setMetadata(metaData)
      .build();
}
 
Example 3
Source File: LocalPlayerActivity.java    From cast-videos-android with Apache License 2.0 5 votes vote down vote up
private MediaInfo buildMediaInfo() {
    MediaMetadata movieMetadata = new MediaMetadata(MediaMetadata.MEDIA_TYPE_MOVIE);

    movieMetadata.putString(MediaMetadata.KEY_SUBTITLE, mSelectedMedia.getStudio());
    movieMetadata.putString(MediaMetadata.KEY_TITLE, mSelectedMedia.getTitle());
    movieMetadata.addImage(new WebImage(Uri.parse(mSelectedMedia.getImage(0))));
    movieMetadata.addImage(new WebImage(Uri.parse(mSelectedMedia.getImage(1))));

    return new MediaInfo.Builder(mSelectedMedia.getUrl())
            .setStreamType(MediaInfo.STREAM_TYPE_BUFFERED)
            .setContentType("videos/mp4")
            .setMetadata(movieMetadata)
            .setStreamDuration(mSelectedMedia.getDuration() * 1000)
            .build();
}
 
Example 4
Source File: ChromeCastMediaPlayer.java    From DeviceConnect-Android with MIT License 5 votes vote down vote up
/**
 * メディアをロードする.
 * 
 * @param   response    レスポンス
 * @param   url         メディアのURL
 * @param   title       メディアのタイトル
 */
public void load(final Intent response, final String url, final String title) {
    MediaInfo mediaInfo;
    
    MediaMetadata mediaMetadata = new MediaMetadata(MediaMetadata.MEDIA_TYPE_MOVIE);
    mediaMetadata.putString(MediaMetadata.KEY_TITLE, title);
    String ext = MimeTypeMap.getFileExtensionFromUrl(url).toLowerCase(Locale.getDefault());
    String mimeType = MimeTypeMap.getSingleton().getMimeTypeFromExtension(ext);
    if (mimeType == null || mimeType.isEmpty()) {
        mimeType = "application/octet-stream";
    }
    mediaInfo = new MediaInfo.Builder(url).setContentType(mimeType)
            .setStreamType(MediaInfo.STREAM_TYPE_BUFFERED)
            .setMetadata(mediaMetadata).build();
    if (mRemoteMediaPlayer != null) {
        try {
            mRemoteMediaPlayer
                    .load(mController.getGoogleApiClient(), mediaInfo, false)
                    .setResultCallback((result) -> {
                        if (result.getStatus().isSuccess()) {
                            mIsLoadEnable = true;
                        } else {
                            mIsLoadEnable = false;
                        }
                        mCallbacks.onChromeCastMediaPlayerResult(response, result, "load");
                    });
        } catch (Exception e) {
            if (BuildConfig.DEBUG) {
                e.printStackTrace();
            }
            mCallbacks.onChromeCastMediaPlayerResult(response, null, "load");
        }
    }
}
 
Example 5
Source File: VideoDetailsFragment.java    From Loop with Apache License 2.0 5 votes vote down vote up
private MediaInfo buildMediaInfo() {
    MediaMetadata movieMetadata = new MediaMetadata(MediaMetadata.MEDIA_TYPE_MOVIE);

    movieMetadata.putString(MediaMetadata.KEY_SUBTITLE, video.getUser().getName());
    movieMetadata.putString(MediaMetadata.KEY_TITLE, video.getName());
    movieMetadata.addImage(new WebImage(Uri.parse(video.getThumbnailUrl())));

    return new MediaInfo.Builder(videoUrl)
            .setStreamType(MediaInfo.STREAM_TYPE_BUFFERED)
            .setContentType("videos/mp4")
            .setMetadata(movieMetadata)
            .setStreamDuration(exoPlayer.getDuration() * 1000)
            .build();
}
 
Example 6
Source File: GoogleCastDelegate.java    From edx-app-android with Apache License 2.0 5 votes vote down vote up
private MediaInfo buildMediaInfo(@NonNull DownloadEntry videoEntry, @NonNull String videoUrl) {
    final MediaMetadata movieMetadata = new MediaMetadata(MediaMetadata.MEDIA_TYPE_MOVIE);

    movieMetadata.putString(MediaMetadata.KEY_TITLE, videoEntry.title);
    movieMetadata.addImage(new WebImage(Uri.parse(videoEntry.videoThumbnail)));

    return new MediaInfo.Builder(videoUrl)
            .setStreamType(MediaInfo.STREAM_TYPE_BUFFERED)
            .setContentType("videos/*")
            .setMetadata(movieMetadata)
            .setStreamDuration(videoEntry.getDuration() * 1000)
            .build();
}
 
Example 7
Source File: MainActivity.java    From AndroidDemoProjects with Apache License 2.0 5 votes vote down vote up
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int position, long l) {
    if( CastContext.getSharedInstance(this).getSessionManager().getCurrentCastSession() != null
            && CastContext.getSharedInstance(this).getSessionManager().getCurrentCastSession().getRemoteMediaClient() != null ) {

        RemoteMediaClient remoteMediaClient = CastContext.getSharedInstance(this).getSessionManager().getCurrentCastSession().getRemoteMediaClient();


        if( remoteMediaClient.getMediaInfo() != null &&
                remoteMediaClient.getMediaInfo().getMetadata() != null
                && mAdapter.getItem(position).equalsIgnoreCase(
                    remoteMediaClient.getMediaInfo().getMetadata().getString(MediaMetadata.KEY_TITLE))) {

            startActivity(new Intent(this, ExpandedControlsActivity.class));

        } else {
            MediaMetadata metadata = new MediaMetadata(MediaMetadata.MEDIA_TYPE_MOVIE);

            metadata.putString(MediaMetadata.KEY_TITLE, mAdapter.getItem(position));
            metadata.putString(MediaMetadata.KEY_SUBTITLE, "Subtitle");
            metadata.addImage(new WebImage(Uri.parse(getString(R.string.movie_poster))));
            metadata.addImage(new WebImage(Uri.parse(getString(R.string.movie_poster))));

            MediaInfo mediaInfo = new MediaInfo.Builder(getString(R.string.movie_link))
                    .setStreamType(MediaInfo.STREAM_TYPE_BUFFERED)
                    .setContentType("videos/mp4")
                    .setMetadata(metadata)
                    .build();


            remoteMediaClient.load(mediaInfo, true, 0);
        }
    } else {
        startActivity(new Intent(this, MovieDetailActivity.class));
    }
}
 
Example 8
Source File: CastActivity.java    From UTubeTV with The Unlicense 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_cast);

  mCastManager = MainApplication.getCastManager(this);

  getActionBar().setDisplayHomeAsUpEnabled(false);
  getActionBar().setDisplayUseLogoEnabled(false);
  getActionBar().setDisplayShowHomeEnabled(false);
  getActionBar().setDisplayShowTitleEnabled(false);

  setupMiniController();
  setupCastListener();

  MediaMetadata movieMetadata = new MediaMetadata(MediaMetadata.MEDIA_TYPE_MOVIE);

  movieMetadata.putString(MediaMetadata.KEY_SUBTITLE, "Animal Fats");
  movieMetadata.putString(MediaMetadata.KEY_TITLE, "Stuff that Sucks");
  movieMetadata.putString(MediaMetadata.KEY_STUDIO, "Google");
  movieMetadata.addImage(new WebImage(Uri.parse("http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/images_480x270/ForBiggerEscapes.jpg")));
  movieMetadata.addImage(new WebImage(Uri.parse("http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/images_780x1200/Escape-780x1200.jpg")));

  mSelectedMedia = new MediaInfo.Builder("http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/ForBiggerEscapes.mp4")
      .setStreamType(MediaInfo.STREAM_TYPE_BUFFERED)
      .setContentType("video/mp4")
      .setMetadata(movieMetadata)
      .build();

  View button = findViewById(R.id.play_button);
  button.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
      togglePlayback();
    }
  });
}
 
Example 9
Source File: MediaInfoBuilder.java    From react-native-google-cast with MIT License 4 votes vote down vote up
public static @NonNull MediaInfo buildMediaInfo(@NonNull ReadableMap parameters) {
    MediaMetadata movieMetadata = new MediaMetadata(MediaMetadata.MEDIA_TYPE_MOVIE);

    String title = ReadableMapUtils.getString(parameters, "title");
    if (title != null) {
        movieMetadata.putString(MediaMetadata.KEY_TITLE, title);
    }

    String subtitle = ReadableMapUtils.getString(parameters, "subtitle");
    if (subtitle != null) {
        movieMetadata.putString(MediaMetadata.KEY_SUBTITLE, subtitle);
    }

    String studio = ReadableMapUtils.getString(parameters, "studio");
    if (studio != null) {
        movieMetadata.putString(MediaMetadata.KEY_STUDIO, studio);
    }

    String imageUrl = ReadableMapUtils.getString(parameters, "imageUrl");
    if (imageUrl != null) {
        movieMetadata.addImage(new WebImage(Uri.parse(imageUrl)));
    }

    String posterUrl = ReadableMapUtils.getString(parameters, "posterUrl");
    if (posterUrl != null) {
        movieMetadata.addImage(new WebImage(Uri.parse(posterUrl)));
    }

    String mediaUrl = ReadableMapUtils.getString(parameters, "mediaUrl");
    if (mediaUrl == null) {
        throw new IllegalArgumentException("mediaUrl option is required");
    }

    Boolean isLive = ReadableMapUtils.getBoolean(parameters, "isLive");
    int streamType =
            isLive != null && isLive
                    ? MediaInfo.STREAM_TYPE_LIVE
                    : MediaInfo.STREAM_TYPE_BUFFERED;

    MediaInfo.Builder builder =
            new MediaInfo.Builder(mediaUrl)
                    .setStreamType(streamType)
                    .setMetadata(movieMetadata);

    String contentType = ReadableMapUtils.getString(parameters, "contentType");
    builder = builder.setContentType(contentType != null ? contentType : DEFAULT_CONTENT_TYPE);

    Map<?, ?> customData = ReadableMapUtils.getMap(parameters, "customData");
    if (customData != null) {
        builder = builder.setCustomData(new JSONObject(customData));
    }

    Integer streamDuration = ReadableMapUtils.getInt(parameters, "streamDuration");
    if (streamDuration != null) {
        builder = builder.setStreamDuration(streamDuration);
    }

    ReadableMap textTrackStyle = ReadableMapUtils.getReadableMap(parameters, "textTrackStyle");
    if (textTrackStyle != null) {
        builder = builder.setTextTrackStyle(buildTextTrackStyle(textTrackStyle));
    }

    return builder.build();
}