Java Code Examples for com.google.android.gms.cast.MediaInfo#STREAM_TYPE_LIVE

The following examples show how to use com.google.android.gms.cast.MediaInfo#STREAM_TYPE_LIVE . 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: VideoCastNotificationService.java    From UTubeTV with The Unlicense 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 2
Source File: VideoCastControllerFragment.java    From UTubeTV with The Unlicense 6 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);
}
 
Example 3
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 4
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 5
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 6
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 7
Source File: VideoCastControllerActivity.java    From UTubeTV with The Unlicense 5 votes vote down vote up
@Override
public void setPlaybackStatus(int state) {
  switch (state) {
    case MediaStatus.PLAYER_STATE_PLAYING:
      mLoading.setVisibility(View.INVISIBLE);
      mPlayPause.setVisibility(View.VISIBLE);

      if (mStreamType == MediaInfo.STREAM_TYPE_LIVE) {
        mPlayPause.setImageDrawable(mStopDrawable);
      } else {
        mPlayPause.setImageDrawable(mPauseDrawable);
      }

      mLine2.setText(getString(R.string.casting_to_device, mCastManager.getDeviceName()));
      mControllers.setVisibility(View.VISIBLE);
      break;
    case MediaStatus.PLAYER_STATE_PAUSED:
      mControllers.setVisibility(View.VISIBLE);
      mLoading.setVisibility(View.INVISIBLE);
      mPlayPause.setVisibility(View.VISIBLE);
      mPlayPause.setImageDrawable(mPlayDrawable);
      mLine2.setText(getString(R.string.casting_to_device, mCastManager.getDeviceName()));
      break;
    case MediaStatus.PLAYER_STATE_IDLE:
      mLoading.setVisibility(View.INVISIBLE);
      mPlayPause.setImageDrawable(mPlayDrawable);
      mPlayPause.setVisibility(View.VISIBLE);
      mLine2.setText(getString(R.string.casting_to_device, mCastManager.getDeviceName()));
      break;
    case MediaStatus.PLAYER_STATE_BUFFERING:
      mPlayPause.setVisibility(View.INVISIBLE);
      mLoading.setVisibility(View.VISIBLE);
      mLine2.setText(getString(R.string.loading));
      break;
    default:
      break;
  }
}
 
Example 8
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 9
Source File: MiniController.java    From android with Apache License 2.0 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 10
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);
}
 
Example 11
Source File: VideoMediaRouteControllerDialog.java    From android with Apache License 2.0 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 12
Source File: MiniController.java    From android with Apache License 2.0 4 votes vote down vote up
@Override
public void setPlaybackStatus(int state, int idleReason) {
    switch (state) {
        case MediaStatus.PLAYER_STATE_PLAYING:
            mPlayPause.setVisibility(View.VISIBLE);
            mPlayPause.setImageDrawable(getPauseStopButton());
            setLoadingVisibility(false);
            break;
        case MediaStatus.PLAYER_STATE_PAUSED:
            mPlayPause.setVisibility(View.VISIBLE);
            mPlayPause.setImageDrawable(mPlayDrawable);
            setLoadingVisibility(false);
            break;
        case MediaStatus.PLAYER_STATE_IDLE:
            switch (mStreamType) {
                case MediaInfo.STREAM_TYPE_BUFFERED:
                    mPlayPause.setVisibility(View.INVISIBLE);
                    setLoadingVisibility(false);
                    break;
                case MediaInfo.STREAM_TYPE_LIVE:
                    if (idleReason == MediaStatus.IDLE_REASON_CANCELED) {
                        mPlayPause.setVisibility(View.VISIBLE);
                        mPlayPause.setImageDrawable(mPlayDrawable);
                        setLoadingVisibility(false);
                    } else {
                        mPlayPause.setVisibility(View.INVISIBLE);
                        setLoadingVisibility(false);
                    }
                    break;
            }
            break;
        case MediaStatus.PLAYER_STATE_BUFFERING:
            mPlayPause.setVisibility(View.INVISIBLE);
            setLoadingVisibility(true);
            break;
        default:
            mPlayPause.setVisibility(View.INVISIBLE);
            setLoadingVisibility(false);
            break;
    }
}
 
Example 13
Source File: VideoMediaRouteControllerDialog.java    From UTubeTV with The Unlicense 4 votes vote down vote up
private void updatePlayPauseState(int state) {
  if (null != mPausePlay) {
    switch (state) {
      case MediaStatus.PLAYER_STATE_PLAYING:
        mPausePlay.setVisibility(View.VISIBLE);
        mPausePlay.setImageDrawable(getPauseStopButton());
        setLoadingVisibility(false);
        break;
      case MediaStatus.PLAYER_STATE_PAUSED:
        mPausePlay.setVisibility(View.VISIBLE);
        mPausePlay.setImageDrawable(mPlayDrawable);
        setLoadingVisibility(false);
        break;
      case MediaStatus.PLAYER_STATE_IDLE:
        mPausePlay.setVisibility(View.INVISIBLE);
        setLoadingVisibility(false);

        if (mState == MediaStatus.PLAYER_STATE_IDLE && mCastManager.getIdleReason() == MediaStatus.IDLE_REASON_FINISHED) {
          hideControls(true, R.string.no_media_info);
        } else {
          switch (mStreamType) {
            case MediaInfo.STREAM_TYPE_BUFFERED:
              mPausePlay.setVisibility(View.INVISIBLE);
              setLoadingVisibility(false);
              break;
            case MediaInfo.STREAM_TYPE_LIVE:
              int idleReason = mCastManager.getIdleReason();
              if (idleReason == MediaStatus.IDLE_REASON_CANCELED) {
                mPausePlay.setVisibility(View.VISIBLE);
                mPausePlay.setImageDrawable(mPlayDrawable);
                setLoadingVisibility(false);
              } else {
                mPausePlay.setVisibility(View.INVISIBLE);
                setLoadingVisibility(false);
              }
              break;
          }
        }
        break;
      case MediaStatus.PLAYER_STATE_BUFFERING:
        mPausePlay.setVisibility(View.INVISIBLE);
        setLoadingVisibility(true);
        break;
      default:
        mPausePlay.setVisibility(View.INVISIBLE);
        setLoadingVisibility(false);
    }
  }
}
 
Example 14
Source File: VideoCastControllerActivity.java    From android with Apache License 2.0 4 votes vote down vote up
@Override
public void setPlaybackStatus(int state) {
    LOGD(TAG, "setPlaybackStatus(): state = " + state);
    switch (state) {
        case MediaStatus.PLAYER_STATE_PLAYING:
            mLoading.setVisibility(View.INVISIBLE);
            mPlayPause.setVisibility(View.VISIBLE);

            if (mStreamType == MediaInfo.STREAM_TYPE_LIVE) {
                mPlayPause.setImageDrawable(mStopDrawable);
            } else {
                mPlayPause.setImageDrawable(mPauseDrawable);
            }

            mLine2.setText(getString(R.string.casting_to_device,
                    mCastManager.getDeviceName()));
            mControllers.setVisibility(View.VISIBLE);
            break;
        case MediaStatus.PLAYER_STATE_PAUSED:
            mControllers.setVisibility(View.VISIBLE);
            mLoading.setVisibility(View.INVISIBLE);
            mPlayPause.setVisibility(View.VISIBLE);
            mPlayPause.setImageDrawable(mPlayDrawable);
            mLine2.setText(getString(R.string.casting_to_device,
                    mCastManager.getDeviceName()));
            break;
        case MediaStatus.PLAYER_STATE_IDLE:
            mLoading.setVisibility(View.INVISIBLE);
            mPlayPause.setImageDrawable(mPlayDrawable);
            mPlayPause.setVisibility(View.VISIBLE);
            mLine2.setText(getString(R.string.casting_to_device,
                    mCastManager.getDeviceName()));
            break;
        case MediaStatus.PLAYER_STATE_BUFFERING:
            mPlayPause.setVisibility(View.INVISIBLE);
            mLoading.setVisibility(View.VISIBLE);
            mLine2.setText(getString(R.string.loading));
            break;
        default:
            break;
    }
}
 
Example 15
Source File: VideoMediaRouteControllerDialog.java    From android with Apache License 2.0 4 votes vote down vote up
private void updatePlayPauseState(int state) {
    if (null != mPausePlay) {
        switch (state) {
            case MediaStatus.PLAYER_STATE_PLAYING:
                mPausePlay.setImageDrawable(getPauseStopButton());
                adjustControlsVisibility(true);
                break;
            case MediaStatus.PLAYER_STATE_PAUSED:
                mPausePlay.setImageDrawable(mPlayDrawable);
                adjustControlsVisibility(true);
                break;
            case MediaStatus.PLAYER_STATE_IDLE:
                mPausePlay.setVisibility(View.INVISIBLE);
                setLoadingVisibility(false);

                if (mState == MediaStatus.PLAYER_STATE_IDLE
                        && mCastManager.getIdleReason() == MediaStatus.IDLE_REASON_FINISHED) {
                    hideControls(true, R.string.no_media_info);
                } else {
                    switch (mStreamType) {
                        case MediaInfo.STREAM_TYPE_BUFFERED:
                            mPausePlay.setVisibility(View.INVISIBLE);
                            setLoadingVisibility(false);
                            break;
                        case MediaInfo.STREAM_TYPE_LIVE:
                            int idleReason = mCastManager.getIdleReason();
                            if (idleReason == MediaStatus.IDLE_REASON_CANCELED) {
                                mPausePlay.setImageDrawable(mPlayDrawable);
                                adjustControlsVisibility(true);
                            } else {
                                mPausePlay.setVisibility(View.INVISIBLE);
                                setLoadingVisibility(false);
                            }
                            break;
                    }
                }
                break;
            case MediaStatus.PLAYER_STATE_BUFFERING:
                adjustControlsVisibility(false);
                break;
            default:
                mPausePlay.setVisibility(View.INVISIBLE);
                setLoadingVisibility(false);
        }
    }
}
 
Example 16
Source File: MiniController.java    From UTubeTV with The Unlicense 4 votes vote down vote up
@Override
public void setPlaybackStatus(int state, int idleReason) {
  switch (state) {
    case MediaStatus.PLAYER_STATE_PLAYING:
      mPlayPause.setVisibility(View.VISIBLE);
      mPlayPause.setImageDrawable(getPauseStopButton());
      setLoadingVisibility(false);
      break;
    case MediaStatus.PLAYER_STATE_PAUSED:
      mPlayPause.setVisibility(View.VISIBLE);
      mPlayPause.setImageDrawable(mPlayDrawable);
      setLoadingVisibility(false);
      break;
    case MediaStatus.PLAYER_STATE_IDLE:
      switch (mStreamType) {
        case MediaInfo.STREAM_TYPE_BUFFERED:
          mPlayPause.setVisibility(View.INVISIBLE);
          setLoadingVisibility(false);
          break;
        case MediaInfo.STREAM_TYPE_LIVE:
          if (idleReason == MediaStatus.IDLE_REASON_CANCELED) {
            mPlayPause.setVisibility(View.VISIBLE);
            mPlayPause.setImageDrawable(mPlayDrawable);
            setLoadingVisibility(false);
          } else {
            mPlayPause.setVisibility(View.INVISIBLE);
            setLoadingVisibility(false);
          }
          break;
      }
      break;
    case MediaStatus.PLAYER_STATE_BUFFERING:
      mPlayPause.setVisibility(View.INVISIBLE);
      setLoadingVisibility(true);
      break;
    default:
      mPlayPause.setVisibility(View.INVISIBLE);
      setLoadingVisibility(false);
      break;
  }
}
 
Example 17
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();
}
 
Example 18
Source File: VideoCastManager.java    From android with Apache License 2.0 3 votes vote down vote up
/**
 * Determines if the media that is loaded remotely is a live stream or not.
 *
 * @return
 * @throws TransientNetworkDisconnectionException
 * @throws NoConnectionException
 */
public final boolean isRemoteStreamLive() throws TransientNetworkDisconnectionException,
        NoConnectionException {
    checkConnectivity();
    MediaInfo info = getRemoteMediaInformation();
    return null != info && info.getStreamType() == MediaInfo.STREAM_TYPE_LIVE;
}
 
Example 19
Source File: VideoCastManager.java    From UTubeTV with The Unlicense 2 votes vote down vote up
/**
 * Determines if the media that is loaded remotely is a live stream or not.
 *
 * @return
 * @throws TransientNetworkDisconnectionException
 * @throws NoConnectionException
 */
public final boolean isRemoteStreamLive() throws TransientNetworkDisconnectionException, NoConnectionException {
  checkConnectivity();
  MediaInfo info = getRemoteMediaInformation();
  return null != info && info.getStreamType() == MediaInfo.STREAM_TYPE_LIVE;
}