com.google.android.gms.common.images.WebImage Java Examples

The following examples show how to use com.google.android.gms.common.images.WebImage. 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: CastOptionsProvider.java    From DeviceConnect-Android with MIT License 6 votes vote down vote up
@Override
public WebImage onPickImage(MediaMetadata mediaMetadata, int type) {
    if ((mediaMetadata == null) || !mediaMetadata.hasImages()) {
        return null;
    }
    List<WebImage> images = mediaMetadata.getImages();
    if (images.size() == 1) {
        return images.get(0);
    } else {
        if (type == ImagePicker.IMAGE_TYPE_MEDIA_ROUTE_CONTROLLER_DIALOG_BACKGROUND) {
            return images.get(0);
        } else {
            return images.get(1);
        }
    }
}
 
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: CastUtils.java    From UTubeTV with The Unlicense 6 votes vote down vote up
/**
 * Builds and returns a {@link Bundle} which contains a select subset of data in the
 * {@link MediaInfo}. Since {@link MediaInfo} is not {@link Parcelable}, one can use this
 * container bundle to pass around from one activity to another.
 */
public static Bundle fromMediaInfo(MediaInfo info) {
  if (null == info) {
    return null;
  }

  MediaMetadata md = info.getMetadata();
  Bundle wrapper = new Bundle();
  wrapper.putString(MediaMetadata.KEY_TITLE, md.getString(MediaMetadata.KEY_TITLE));
  wrapper.putString(MediaMetadata.KEY_SUBTITLE, md.getString(MediaMetadata.KEY_SUBTITLE));
  wrapper.putString(KEY_URL, info.getContentId());
  wrapper.putString(MediaMetadata.KEY_STUDIO, md.getString(MediaMetadata.KEY_STUDIO));
  wrapper.putString(KEY_CONTENT_TYPE, info.getContentType());
  wrapper.putInt(KEY_STREAM_TYPE, info.getStreamType());
  if (null != md.getImages()) {
    ArrayList<String> urls = new ArrayList<String>();
    for (WebImage img : md.getImages()) {
      urls.add(img.getUrl().toString());
    }
    wrapper.putStringArrayList(KEY_IMAGES, urls);
  }

  return wrapper;
}
 
Example #4
Source File: CastDeviceControllerImpl.java    From android_packages_apps_GmsCore with Apache License 2.0 6 votes vote down vote up
protected ApplicationMetadata createMetadataFromApplication(Application app) {
    if (app == null) {
        return null;
    }
    ApplicationMetadata metadata = new ApplicationMetadata();
    metadata.applicationId = app.id;
    metadata.name = app.name;
    Log.d(TAG, "unimplemented: ApplicationMetadata.images");
    Log.d(TAG, "unimplemented: ApplicationMetadata.senderAppLaunchUri");
    metadata.images = new ArrayList<WebImage>();
    metadata.namespaces = new ArrayList<String>();
    for(Namespace namespace : app.namespaces) {
        metadata.namespaces.add(namespace.name);
    }
    metadata.senderAppIdentifier = this.context.getPackageName();
    return metadata;
}
 
Example #5
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 #6
Source File: GoogleCastOptionsProvider.java    From react-native-google-cast with MIT License 6 votes vote down vote up
@Override
public WebImage onPickImage(MediaMetadata mediaMetadata, int type) {
  if ((mediaMetadata == null) || !mediaMetadata.hasImages()) {
    return null;
  }
  List<WebImage> images = mediaMetadata.getImages();
  if (images.size() == 1) {
    return images.get(0);
  } else {
    if (type ==
        ImagePicker.IMAGE_TYPE_MEDIA_ROUTE_CONTROLLER_DIALOG_BACKGROUND) {
      return images.get(0);
    } else {
      return images.get(1);
    }
  }
}
 
Example #7
Source File: CastOptionsProvider.java    From CastVideos-android with Apache License 2.0 6 votes vote down vote up
@Override
public WebImage onPickImage(MediaMetadata mediaMetadata, int type) {
    if ((mediaMetadata == null) || !mediaMetadata.hasImages()) {
        return null;
    }
    List<WebImage> images = mediaMetadata.getImages();
    if (images.size() == 1) {
        return images.get(0);
    } else {
        if (type == ImagePicker.IMAGE_TYPE_MEDIA_ROUTE_CONTROLLER_DIALOG_BACKGROUND) {
            return images.get(0);
        } else {
            return images.get(1);
        }
    }
}
 
Example #8
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 #9
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 #10
Source File: Utils.java    From android with Apache License 2.0 5 votes vote down vote up
/**
 * Builds and returns a {@link Bundle} which contains a select subset of data in the
 * {@link MediaInfo}. Since {@link MediaInfo} is not {@link Parcelable}, one can use this
 * container bundle to pass around from one activity to another.
 *
 * @param info
 * @return
 * @see <code>toMediaInfo()</code>
 */
public static Bundle fromMediaInfo(MediaInfo info) {
    if (null == info) {
        return null;
    }

    MediaMetadata md = info.getMetadata();
    Bundle wrapper = new Bundle();
    wrapper.putString(MediaMetadata.KEY_TITLE, md.getString(MediaMetadata.KEY_TITLE));
    wrapper.putString(MediaMetadata.KEY_SUBTITLE, md.getString(MediaMetadata.KEY_SUBTITLE));
    wrapper.putString(KEY_URL, info.getContentId());
    wrapper.putString(MediaMetadata.KEY_STUDIO, md.getString(MediaMetadata.KEY_STUDIO));
    wrapper.putString(KEY_CONTENT_TYPE, info.getContentType());
    wrapper.putInt(KEY_STREAM_TYPE, info.getStreamType());
    if (!md.getImages().isEmpty()) {
        ArrayList<String> urls = new ArrayList<String>();
        for (WebImage img : md.getImages()) {
            urls.add(img.getUrl().toString());
        }
        wrapper.putStringArrayList(KEY_IMAGES, urls);
    }
    JSONObject customData = info.getCustomData();
    if (null != customData) {
        wrapper.putString(KEY_CUSTOM_DATA, customData.toString());
    }

    return wrapper;
}
 
Example #11
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 #12
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 #13
Source File: CastOptionsProvider.java    From edx-app-android with Apache License 2.0 5 votes vote down vote up
@Override
public WebImage onPickImage(MediaMetadata mediaMetadata, @NonNull ImageHints imageHints) {
    if ((mediaMetadata == null) || !mediaMetadata.hasImages()) {
        return null;
    }
    return mediaMetadata.getImages().get(0);
}
 
Example #14
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 #15
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 #16
Source File: BaseActivity.java    From SkyTube with GNU General Public License v3.0 4 votes vote down vote up
public void playVideoOnChromecast(final YouTubeVideo video, final int position) {
	showLoadingSpinner();
	if(video.getDescription() == null) {
		new GetVideoDescriptionTask(video, description -> {
			playVideoOnChromecast(video, position);
		}).executeInParallel();
	} else {
		video.getDesiredStream(new GetDesiredStreamListener() {
			@Override
			public void onGetDesiredStream(StreamMetaData desiredStream) {
				if(mCastSession == null)
					return;
				Gson gson = new Gson();
				final RemoteMediaClient remoteMediaClient = mCastSession.getRemoteMediaClient();
				MediaMetadata metadata = new MediaMetadata(MediaMetadata.MEDIA_TYPE_GENERIC);
				metadata.putInt(KEY_POSITION, position);
				metadata.putString(KEY_VIDEO, gson.toJson(video));

				metadata.addImage(new WebImage(Uri.parse(video.getThumbnailUrl())));

				MediaInfo currentPlayingMedia = new MediaInfo.Builder(desiredStream.getUri().toString())
								.setStreamType(MediaInfo.STREAM_TYPE_BUFFERED)
								.setContentType(desiredStream.getFormat().mimeType)
								.setMetadata(metadata)
								.build();

				MediaLoadOptions options = new MediaLoadOptions.Builder().setAutoplay(true).setPlayPosition(0).build();
				remoteMediaClient.load(currentPlayingMedia, options);
				chromecastMiniControllerFragment.init(remoteMediaClient, currentPlayingMedia, position);
				chromecastControllerFragment.init(remoteMediaClient, currentPlayingMedia, position);
				// If the Controller panel isn't visible, setting the progress of the progressbar in the mini controller won't
				// work until the panel is visible, so do it as soon as the sliding panel is visible. Adding this listener when
				// the panel is not hidden will lead to a java.util.ConcurrentModificationException the next time a video is
				// switching from local playback to chromecast, so we should only do this if the panel is hidden.
				if(slidingLayout.getPanelState() == SlidingUpPanelLayout.PanelState.HIDDEN) {
					slidingLayout.addPanelSlideListener(getOnPanelDisplayed(position, video.getDurationInSeconds()*1000));
				}
			}

			@Override
			public void onGetDesiredStreamError(String errorMessage) {
				if (errorMessage != null) {
					if(chromecastLoadingSpinner != null)
						chromecastLoadingSpinner.setVisibility(View.GONE);
					new AlertDialog.Builder(BaseActivity.this)
									.setMessage(errorMessage)
									.setTitle(R.string.error_video_play)
									.setCancelable(false)
									.setPositiveButton(R.string.ok, (dialog, which) -> {
									})
									.show();
				}
			}
		});
	}
}
 
Example #17
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 #18
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();
}