com.google.android.gms.cast.MediaInfo Java Examples

The following examples show how to use com.google.android.gms.cast.MediaInfo. 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: VideoCastManager.java    From android with Apache License 2.0 6 votes vote down vote up
private void updateLockScreenImage(final MediaInfo info) {
    if (null == info) {
        return;
    }
    new Thread(new Runnable() {
        @Override
        public void run() {
            if (null == mRemoteControlClientCompat) {
                return;
            }
            try {
                Bitmap bm = getBitmapForLockScreen(info);
                if (null == bm) {
                    return;
                }
                mRemoteControlClientCompat.editMetadata(false).putBitmap(
                        RemoteControlClientCompat.MetadataEditorCompat.
                                METADATA_KEY_ARTWORK, bm
                ).apply();
            } catch (Exception e) {
                LOGD(TAG, "Failed to update lock screen image", e);
            }
        }
    }).start();
}
 
Example #2
Source File: GoogleCastRemoteMediaClientListener.java    From react-native-google-cast with MIT License 6 votes vote down vote up
@NonNull
private WritableMap prepareMessage(MediaStatus mediaStatus) {
  // needs to be constructed for every message from scratch because reusing a
  // message fails with "Map already consumed"
  WritableMap map = Arguments.createMap();
  map.putInt("playerState", mediaStatus.getPlayerState());
  map.putInt("idleReason", mediaStatus.getIdleReason());
  map.putBoolean("muted", mediaStatus.isMute());
  map.putInt("streamPosition", (int)(mediaStatus.getStreamPosition() / 1000));

  MediaInfo info = mediaStatus.getMediaInfo();
  if (info != null) {
    map.putInt("streamDuration", (int) (info.getStreamDuration() / 1000));
  }

  WritableMap message = Arguments.createMap();
  message.putMap("mediaStatus", map);
  return message;
}
 
Example #3
Source File: VideoCastNotificationService.java    From android with Apache License 2.0 6 votes vote down vote up
private void addPendingIntents(RemoteViews rv, boolean isPlaying, MediaInfo info) {
    Intent playbackIntent = new Intent(ACTION_TOGGLE_PLAYBACK);
    playbackIntent.setPackage(getPackageName());
    PendingIntent playbackPendingIntent = PendingIntent
            .getBroadcast(this, 0, playbackIntent, 0);

    Intent stopIntent = new Intent(ACTION_STOP);
    stopIntent.setPackage(getPackageName());
    PendingIntent stopPendingIntent = PendingIntent.getBroadcast(this, 0, stopIntent, 0);

    rv.setOnClickPendingIntent(R.id.playPauseView, playbackPendingIntent);
    rv.setOnClickPendingIntent(R.id.removeView, stopPendingIntent);

    if (isPlaying) {
        if (info.getStreamType() == MediaInfo.STREAM_TYPE_LIVE) {
            rv.setImageViewResource(R.id.playPauseView, R.drawable.ic_av_stop_sm_dark);
        } else {
            rv.setImageViewResource(R.id.playPauseView, R.drawable.ic_av_pause_sm_dark);
        }

    } else {
        rv.setImageViewResource(R.id.playPauseView, R.drawable.ic_av_play_sm_dark);
    }
}
 
Example #4
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 #5
Source File: CastPlayback.java    From klingar with Apache License 2.0 6 votes vote down vote up
private void loadMedia(@NonNull Track track, boolean autoPlay) throws JSONException {
  Timber.d("loadMedia %s %s", track, autoPlay);
  if (!track.equals(currentTrack)) {
    currentTrack = track;
    currentPosition = 0;
  }
  JSONObject customData = new JSONObject();
  customData.put(CUSTOM_DATA_TRACK, jsonAdapter.toJson(track));
  MediaInfo media = toCastMediaMetadata(track, customData);
  MediaLoadOptions loadOptions = new MediaLoadOptions.Builder()
      .setAutoplay(autoPlay)
      .setPlayPosition(currentPosition)
      .setCustomData(customData)
      .build();
  remoteMediaClient.load(media, loadOptions);
}
 
Example #6
Source File: ChromecastMiniControllerFragment.java    From SkyTube with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void init(RemoteMediaClient client, MediaInfo media, int position) {
	super.init(client, media, position);

	videoTitle.setText(video.getTitle());
	channelName.setText(video.getChannelName());

	// We just either started playback of a video, or resumed the cast session. In the latter case, if there's a video playing, let the activity
	// know so that the panel will appear.
	if(currentPlayerState != MediaStatus.PLAYER_STATE_IDLE) {
		activityListener.onPlayStarted();
	}
	chromecastMiniControllerLeftContainer.setAlpha(1);
	chromecastMiniControllerRightContainer.setAlpha(1);
	setDuration((int)client.getStreamDuration());
}
 
Example #7
Source File: CastPlayback.java    From klingar with Apache License 2.0 6 votes vote down vote up
private void setMetadataFromRemote() {
  // Sync: We get the customData from the remote media information and update the local
  // metadata if it happens to be different from the one we are currently using.
  // This can happen when the app was either restarted/disconnected + connected, or if the
  // app joins an existing session while the Chromecast was playing a queue.
  try {
    MediaInfo mediaInfo = remoteMediaClient.getMediaInfo();
    if (mediaInfo == null) {
      return;
    }
    JSONObject customData = mediaInfo.getCustomData();
    if (customData != null && customData.has(CUSTOM_DATA_TRACK)) {
      Track remoteTrack = jsonAdapter.fromJson(customData.getString(CUSTOM_DATA_TRACK));
      Timber.d("setMetadataFromRemote %s", remoteTrack);
      if (!Objects.equals(remoteTrack, currentTrack)) {
        currentTrack = remoteTrack;
        if (callback != null) {
          callback.setCurrentTrack(remoteTrack);
        }
        updateLastKnownStreamPosition();
      }
    }
  } catch (JSONException | IOException e) {
    Timber.e(e, "Exception processing update metadata");
  }
}
 
Example #8
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 #9
Source File: VideoBrowserFragment.java    From CastVideos-android with Apache License 2.0 6 votes vote down vote up
@Override
public void itemClicked(View view, MediaInfo item, int position) {
    if (view instanceof ImageButton) {
        Utils.showQueuePopup(getActivity(), view, item);
    } else {
        String transitionName = getString(R.string.transition_image);
        VideoListAdapter.ViewHolder viewHolder =
                (VideoListAdapter.ViewHolder) mRecyclerView.findViewHolderForPosition(position);
        Pair<View, String> imagePair = Pair
                .create((View) viewHolder.getImageView(), transitionName);
        ActivityOptionsCompat options = ActivityOptionsCompat
                .makeSceneTransitionAnimation(getActivity(), imagePair);

        Intent intent = new Intent(getActivity(), LocalPlayerActivity.class);
        intent.putExtra("media", item);
        intent.putExtra("shouldStart", false);
        ActivityCompat.startActivity(getActivity(), intent, options.toBundle());
    }
}
 
Example #10
Source File: ChromeCastMediaPlayer.java    From DeviceConnect-Android with MIT License 6 votes vote down vote up
/**
 * メディアをプレイする.
 * 
 * @param   response    レスポンス
 */
public void play(final Intent response) {
    MediaInfo mediaInfo = null;
    if (mIsLoadEnable) {
        mediaInfo = mRemoteMediaPlayer.getMediaInfo();
    }

    try {
        if (mRemoteMediaPlayer != null) {
            mRemoteMediaPlayer.load(mController.getGoogleApiClient(), mediaInfo, true).setResultCallback(
                (result) -> {
                    mCallbacks.onChromeCastMediaPlayerResult(response, result, "load");
                });
        }
    } catch (Exception e) {
        if (BuildConfig.DEBUG) {
            e.printStackTrace();
        }
        mCallbacks.onChromeCastMediaPlayerResult(response, null, "load");
    }
}
 
Example #11
Source File: VideoCastControllerFragment.java    From android with Apache License 2.0 6 votes vote down vote up
@Override
public void onResult(MediaAuthStatus status, final MediaInfo info, final String message,
                     final int startPoint, final JSONObject customData) {
    if (status == MediaAuthStatus.RESULT_AUTHORIZED && mAuthSuccess) {
        // successful authorization
        mMediaAuthService = null;
        if (null != mMediaAuthTimer) {
            mMediaAuthTimer.cancel();
        }
        mSelectedMedia = info;
        mHandler.post(new Runnable() {

            @Override
            public void run() {
                mOverallState = OverallState.PLAYBACK;
                onReady(info, true, startPoint, customData);
            }
        });
    } else {
        if (null != mMediaAuthTimer) {
            mMediaAuthTimer.cancel();
        }
        mHandler.post(new Runnable() {
 
Example #12
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 #13
Source File: VideoCastManager.java    From android with Apache License 2.0 6 votes vote down vote up
/**
 * Updates the information and state of a MiniController.
 *
 * @throws TransientNetworkDisconnectionException
 * @throws NoConnectionException
 */
private void updateMiniController(IMiniController controller)
        throws TransientNetworkDisconnectionException, NoConnectionException {
    checkConnectivity();
    checkRemoteMediaPlayerAvailable();
    if (mRemoteMediaPlayer.getStreamDuration() > 0 || isRemoteStreamLive()) {
        MediaInfo mediaInfo = getRemoteMediaInformation();
        MediaMetadata mm = mediaInfo.getMetadata();
        controller.setStreamType(mediaInfo.getStreamType());
        controller.setPlaybackStatus(mState, mIdleReason);
        controller.setSubTitle(mContext.getResources().getString(R.string.casting_to_device,
                mDeviceName));
        controller.setTitle(mm.getString(MediaMetadata.KEY_TITLE));
        if (!mm.getImages().isEmpty()) {
            controller.setIcon(mm.getImages().get(0).getUrl());
        }
    }
}
 
Example #14
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 #15
Source File: VideoCastControllerFragment.java    From android with Apache License 2.0 6 votes vote down vote up
private void updateMetadata() {
    String imageUrl = null;
    if (null == mSelectedMedia) {
        if (null != mMediaAuthService) {
            imageUrl = Utils.getImageUrl(mMediaAuthService.getMediaInfo(), 1);
        }
    } else {
        imageUrl = Utils.getImageUrl(mSelectedMedia, 1);
    }
    showImage(imageUrl);
    if (null == mSelectedMedia) {
        return;
    }
    MediaMetadata mm = mSelectedMedia.getMetadata();
    mCastController.setLine1(null != mm.getString(MediaMetadata.KEY_TITLE)
            ? mm.getString(MediaMetadata.KEY_TITLE) : "");
    boolean isLive = mSelectedMedia.getStreamType() == MediaInfo.STREAM_TYPE_LIVE;
    mCastController.adjustControllersForLiveStream(isLive);
}
 
Example #16
Source File: VideoCastControllerFragment.java    From android with Apache License 2.0 6 votes vote down vote up
private void onReady(MediaInfo mediaInfo, boolean shouldStartPlayback, int startPoint,
                     JSONObject customData) {
    mSelectedMedia = mediaInfo;
    try {
        mCastController.setStreamType(mSelectedMedia.getStreamType());
        if (shouldStartPlayback) {
            // need to start remote playback
            mPlaybackState = MediaStatus.PLAYER_STATE_BUFFERING;
            mCastController.setPlaybackStatus(mPlaybackState);
            mCastManager.loadMedia(mSelectedMedia, true, startPoint, customData);
        } else {
            // we don't change the status of remote playback
            if (mCastManager.isRemoteMoviePlaying()) {
                mPlaybackState = MediaStatus.PLAYER_STATE_PLAYING;
            } else {
                mPlaybackState = MediaStatus.PLAYER_STATE_PAUSED;
            }
            mCastController.setPlaybackStatus(mPlaybackState);
        }
    } catch (Exception e) {
        LOGE(TAG, "Failed to get playback and media information", e);
        mCastController.closeActivity();
    }
    updateMetadata();
    restartTrickplayTimer();
}
 
Example #17
Source File: VideoCastControllerFragment.java    From UTubeTV with The Unlicense 6 votes vote down vote up
private void updateMetadata() {
  String imageUrl = null;
  if (null == mSelectedMedia) {
    if (null != mMediaAuthService) {
      imageUrl = CastUtils.getImageUrl(mMediaAuthService.getMediaInfo(), 1);
    }
  } else {
    imageUrl = CastUtils.getImageUrl(mSelectedMedia, 1);
  }
  if (null != imageUrl) {
    showImage(imageUrl);
  }
  if (null == mSelectedMedia) {
    return;
  }
  MediaMetadata mm = mSelectedMedia.getMetadata();
  mCastController.setLine1(mm.getString(MediaMetadata.KEY_TITLE));
  boolean isLive = mSelectedMedia.getStreamType() == MediaInfo.STREAM_TYPE_LIVE;
  mCastController.adjustControllersForLiveStream(isLive);
}
 
Example #18
Source File: VideoCastManager.java    From UTubeTV with The Unlicense 6 votes vote down vote up
/**
 * Loads a media. For this to succeed, you need to have successfully launched the application.
 *
 * @param media
 * @param autoPlay   If <code>true</code>, playback starts after load
 * @param position   Where to start the playback (only used if autoPlay is <code>true</code>.
 *                   Units is milliseconds.
 * @param customData Optional JSONObject data to be passed to the cast device
 * @throws NoConnectionException
 * @throws TransientNetworkDisconnectionException
 */
public void loadMedia(MediaInfo media, boolean autoPlay, int position, JSONObject customData) throws TransientNetworkDisconnectionException, NoConnectionException {
  CastUtils.LOGD(TAG, "loadMedia: " + media);
  checkConnectivity();
  if (media == null) {
    return;
  }
  if (mRemoteMediaPlayer == null) {
    CastUtils.LOGE(TAG, "Trying to load a video with no active media session");
    throw new NoConnectionException();
  }

  mRemoteMediaPlayer.load(mApiClient, media, autoPlay, position, customData)
      .setResultCallback(new ResultCallback<RemoteMediaPlayer.MediaChannelResult>() {

        @Override
        public void onResult(MediaChannelResult result) {
          if (!result.getStatus().isSuccess()) {
            onFailed(R.string.failed_load, result.getStatus().getStatusCode());
          }

        }
      });
}
 
Example #19
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 #20
Source File: VideoCastManager.java    From android with Apache License 2.0 6 votes vote down vote up
/**
 * Loads a media. For this to succeed, you need to have successfully launched the application.
 *
 * @param media
 * @param autoPlay   If <code>true</code>, playback starts after load
 * @param position   Where to start the playback (only used if autoPlay is <code>true</code>).
 *                   Units is milliseconds.
 * @param customData Optional {@link JSONObject} data to be passed to the cast device
 * @throws NoConnectionException
 * @throws TransientNetworkDisconnectionException
 */
public void loadMedia(MediaInfo media, boolean autoPlay, int position, JSONObject customData)
        throws TransientNetworkDisconnectionException, NoConnectionException {
    LOGD(TAG, "loadMedia: " + media);
    checkConnectivity();
    if (media == null) {
        return;
    }
    if (mRemoteMediaPlayer == null) {
        LOGE(TAG, "Trying to load a video with no active media session");
        throw new NoConnectionException();
    }

    mRemoteMediaPlayer.load(mApiClient, media, autoPlay, position, customData)
            .setResultCallback(new ResultCallback<RemoteMediaPlayer.MediaChannelResult>() {

                @Override
                public void onResult(MediaChannelResult result) {
                    if (!result.getStatus().isSuccess()) {
                        onFailed(R.string.failed_load, result.getStatus().getStatusCode());
                    }

                }
            });
}
 
Example #21
Source File: VideoCastManager.java    From UTubeTV with The Unlicense 5 votes vote down vote up
/**
 * *********** RemoteControlClient management **************************
 */

/*
 * Updates lock screen image
 */
private void updateLockScreenImage(final MediaInfo info) {
  if (null == info) {
    return;
  }
  new Thread(new Runnable() {
    @Override
    public void run() {
      if (null == mRemoteControlClient) {
        return;
      }
      try {
        Bitmap bm = getBitmapForLockScreen(info);
        if (null == bm) {
          return;
        }
        mRemoteControlClient.editMetadata(false).putBitmap(RemoteControlClient.MetadataEditor.
            BITMAP_KEY_ARTWORK, bm).apply();
      } catch (Exception e) {
        CastUtils.LOGD(TAG, "Failed to update lock screen image", e);
      }
    }
  }).start();
}
 
Example #22
Source File: VideoCastManager.java    From UTubeTV with The Unlicense 5 votes vote down vote up
/**
 * Updates the information and state of a MiniController.
 */
private void updateMiniController(IMiniController controller) throws TransientNetworkDisconnectionException, NoConnectionException {
  checkConnectivity();
  checkRemoteMediaPlayerAvailable();
  if (mRemoteMediaPlayer.getStreamDuration() > 0) {
    MediaInfo mediaInfo = getRemoteMediaInformation();
    MediaMetadata mm = mediaInfo.getMetadata();
    controller.setStreamType(mediaInfo.getStreamType());
    controller.setPlaybackStatus(mState, mIdleReason);
    controller.setSubTitle(mContext.getResources()
        .getString(R.string.casting_to_device, mDeviceName));
    controller.setTitle(mm.getString(MediaMetadata.KEY_TITLE));
    controller.setIcon(mm.getImages().get(0).getUrl());
  }
}
 
Example #23
Source File: VideoMediaRouteControllerDialog.java    From UTubeTV with The Unlicense 5 votes vote down vote up
private Drawable getPauseStopButton() {
  switch (mStreamType) {
    case MediaInfo.STREAM_TYPE_BUFFERED:
      return mPauseDrawable;
    case MediaInfo.STREAM_TYPE_LIVE:
      return mStopDrawable;
    default:
      return mPauseDrawable;
  }
}
 
Example #24
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 #25
Source File: MiniController.java    From UTubeTV with The Unlicense 5 votes vote down vote up
private Drawable getPauseStopButton() {
  switch (mStreamType) {
    case MediaInfo.STREAM_TYPE_BUFFERED:
      return mPauseDrawable;
    case MediaInfo.STREAM_TYPE_LIVE:
      return mStopDrawable;
    default:
      return mPauseDrawable;
  }
}
 
Example #26
Source File: VideoCastControllerFragment.java    From UTubeTV with The Unlicense 5 votes vote down vote up
@Override
public void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  mCastConsumer = new MyCastConsumer();
  Bundle bundle = getArguments();
  if (null == bundle) {
    return;
  }
  Bundle extras = bundle.getBundle(EXTRAS);
  Bundle mediaWrapper = extras.getBundle(VideoCastManager.EXTRA_MEDIA);

  // Retain this fragment across configuration changes.
  setRetainInstance(true);

  if (extras.getBoolean(VideoCastManager.EXTRA_HAS_AUTH)) {
    mOverallState = OverallState.AUTHORIZING;
    mMediaAuthService = mCastManager.getMediaAuthService();
    handleMediaAuthTask(mMediaAuthService);
    showImage(CastUtils.getImageUrl(mMediaAuthService.getMediaInfo(), 1));
  } else if (null != mediaWrapper) {
    mOverallState = OverallState.PLAYBACK;
    boolean shouldStartPlayback = extras.getBoolean(VideoCastManager.EXTRA_SHOULD_START);
    MediaInfo info = CastUtils.toMediaInfo(mediaWrapper);
    int startPoint = extras.getInt(VideoCastManager.EXTRA_START_POINT, 0);
    onReady(info, shouldStartPlayback, startPoint);
  }
}
 
Example #27
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 #28
Source File: ChromecastControllerFragment.java    From SkyTube with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void init(RemoteMediaClient client, MediaInfo media, int position) {
	super.init(client, media, position);
	if(video != null) {
		setupDescription();
	}
	durationTextView.setMilliseconds(chromecastPlaybackProgressBar.getMax());
	if(media.getMetadata().getImages().size() > 0) {
		Picasso.with(getActivity().getApplicationContext())
						.load(media.getMetadata().getImages().get(0).getUrl().toString())
						.placeholder(R.drawable.thumbnail_default)
						.into(videoImage);
	}
}
 
Example #29
Source File: VideoCastControllerActivity.java    From android with Apache License 2.0 5 votes vote down vote up
@Override
public void updateControllersStatus(boolean enabled) {
    mControllers.setVisibility(enabled ? View.VISIBLE : View.INVISIBLE);
    if (enabled) {
        adjustControllersForLiveStream(mStreamType == MediaInfo.STREAM_TYPE_LIVE);
    }
}
 
Example #30
Source File: VideoCastControllerFragment.java    From android with Apache License 2.0 5 votes vote down vote up
private void togglePlayback() throws CastException, TransientNetworkDisconnectionException,
        NoConnectionException {
    switch (mPlaybackState) {
        case MediaStatus.PLAYER_STATE_PAUSED:
            mCastManager.play();
            mPlaybackState = MediaStatus.PLAYER_STATE_BUFFERING;
            restartTrickplayTimer();
            break;
        case MediaStatus.PLAYER_STATE_PLAYING:
            mCastManager.pause();
            mPlaybackState = MediaStatus.PLAYER_STATE_BUFFERING;
            break;
        case MediaStatus.PLAYER_STATE_IDLE:
            if ((mSelectedMedia.getStreamType() == MediaInfo.STREAM_TYPE_LIVE)
                    && (mCastManager.getIdleReason() == MediaStatus.IDLE_REASON_CANCELED)) {
                mCastManager.play();
            } else {
                mCastManager.loadMedia(mSelectedMedia, true, 0);
            }
            mPlaybackState = MediaStatus.PLAYER_STATE_BUFFERING;
            restartTrickplayTimer();
            break;
        default:
            break;
    }
    mCastController.setPlaybackStatus(mPlaybackState);
}