Java Code Examples for com.google.android.gms.cast.MediaMetadata#addImage()

The following examples show how to use com.google.android.gms.cast.MediaMetadata#addImage() . 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: MediaData.java    From Casty with MIT License 6 votes vote down vote up
MediaInfo createMediaInfo() {
    MediaMetadata mediaMetadata = new MediaMetadata(mediaType);

    if (!TextUtils.isEmpty(title)) mediaMetadata.putString(MediaMetadata.KEY_TITLE, title);
    if (!TextUtils.isEmpty(subtitle)) mediaMetadata.putString(MediaMetadata.KEY_SUBTITLE, subtitle);

    for (String imageUrl : imageUrls) {
        mediaMetadata.addImage(new WebImage(Uri.parse(imageUrl)));
    }

    return new MediaInfo.Builder(url)
            .setStreamType(streamType)
            .setContentType(contentType)
            .setStreamDuration(streamDuration)
            .setMetadata(mediaMetadata)
            .build();
}
 
Example 2
Source File: CastPlayback.java    From klingar with Apache License 2.0 6 votes vote down vote up
private static MediaInfo toCastMediaMetadata(Track track, JSONObject customData) {
  MediaMetadata mediaMetadata = new MediaMetadata(MediaMetadata.MEDIA_TYPE_MUSIC_TRACK);
  mediaMetadata.putString(MediaMetadata.KEY_TITLE, track.title());
  mediaMetadata.putString(MediaMetadata.KEY_SUBTITLE, track.artistTitle());
  mediaMetadata.putString(MediaMetadata.KEY_ALBUM_ARTIST, track.artistTitle());
  mediaMetadata.putString(MediaMetadata.KEY_ALBUM_TITLE, track.albumTitle());
  WebImage image = new WebImage(new Uri.Builder().encodedPath(track.thumb()).build());
  // First image is used by the receiver for showing the audio album art.
  mediaMetadata.addImage(image);
  // Second image is used by Cast Library when the cast dialog is clicked.
  mediaMetadata.addImage(image);

  //noinspection ResourceType
  return new MediaInfo.Builder(track.source())
      .setContentType(MIME_TYPE_AUDIO_MPEG)
      .setStreamType(MediaInfo.STREAM_TYPE_BUFFERED)
      .setMetadata(mediaMetadata)
      .setCustomData(customData)
      .build();
}
 
Example 3
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 4
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 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: StreamFragment.java    From Pocket-Plays-for-Twitch with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Sends the URL to a chromecast (Or android TV) if it is connected.
 *
 * @param videoURL
 */
private void playOnCast(String videoURL) {
    //ToDo: We probably need to make a custom Cast receiver to play a link from Twitch. As Twitch doesnt allow third party receivers to play link from another origin
    // Use https://www.udacity.com/course/progress#!/c-ud875B and
    // https://github.com/googlecast/CastReferencePlayer
    try {
        String logoImageUrl = mChannelInfo.getLogoURLString();
        String streamerName = mChannelInfo.getDisplayName();
        if (mCastContext != null && mCastContext.getCastState() == CastState.CONNECTED) {
            MediaMetadata mediaMetadata = new MediaMetadata();
            mediaMetadata.putString(getString(R.string.stream_fragment_vod_id), vodId);
            mediaMetadata.putInt(getString(R.string.stream_fragment_vod_length), vodLength);
            mediaMetadata.putString(getString(R.string.stream_fragment_streamerInfo), new Gson().toJson(mChannelInfo));
            mediaMetadata.putString(MediaMetadata.KEY_TITLE, streamerName);
            if (logoImageUrl != null) {
                mediaMetadata.addImage(new WebImage(Uri.parse(logoImageUrl)));
            }

            MediaInfo.Builder mediaBuilder = new MediaInfo.Builder(videoURL)
                    .setMetadata(mediaMetadata)
                    .setContentType("application/x-mpegURL");


            if (vodId == null) {
                mediaBuilder
                        .setStreamType(MediaInfo.STREAM_TYPE_LIVE)
                        .setStreamDuration(MediaInfo.UNKNOWN_DURATION);
            } else {
                mediaBuilder
                        .setStreamType(MediaInfo.STREAM_TYPE_BUFFERED)
                        .setStreamDuration(vodLength / 1000);
            }


            CastSession session = mCastContext.getSessionManager().getCurrentCastSession();
            if (session != null) {
                checkChromecastConnection();
                session.getRemoteMediaClient().load(mediaBuilder.build(), true, 0);
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
Example 10
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();
}