Example usage for android.media.tv TvInputManager VIDEO_UNAVAILABLE_REASON_TUNING

List of usage examples for android.media.tv TvInputManager VIDEO_UNAVAILABLE_REASON_TUNING

Introduction

In this page you can find the example usage for android.media.tv TvInputManager VIDEO_UNAVAILABLE_REASON_TUNING.

Prototype

int VIDEO_UNAVAILABLE_REASON_TUNING

To view the source code for android.media.tv TvInputManager VIDEO_UNAVAILABLE_REASON_TUNING.

Click Source Link

Document

Reason for TvInputService.Session#notifyVideoUnavailable(int) and TvView.TvInputCallback#onVideoUnavailable(String,int) : Video is unavailable because the corresponding TV input is in the middle of tuning to a new channel.

Usage

From source file:com.android.tv.ui.TunableTvView.java

/**
 * Plays a recording.//from  w  ww.j av  a2s . c  om
 */
public boolean playRecording(Uri recordingUri, OnTuneListener listener) {
    if (!mStarted) {
        throw new IllegalStateException("TvView isn't started");
    }
    if (!CommonFeatures.DVR.isEnabled(getContext()) || !BuildCompat.isAtLeastN()) {
        return false;
    }
    if (DEBUG)
        Log.d(TAG, "playRecording " + recordingUri);
    long recordingId = ContentUris.parseId(recordingUri);
    mRecordedProgram = mDvrDataManager.getRecordedProgram(recordingId);
    if (mRecordedProgram == null) {
        Log.w(TAG, "No recorded program (Uri=" + recordingUri + ")");
        return false;
    }
    String inputId = mRecordedProgram.getInputId();
    TvInputInfo inputInfo = mInputManagerHelper.getTvInputInfo(inputId);
    if (inputInfo == null) {
        return false;
    }
    mOnTuneListener = listener;
    // mCurrentChannel can be null.
    mCurrentChannel = mChannelDataManager.getChannel(mRecordedProgram.getChannelId());
    // For recording playback, input event should not be sent.
    mCanReceiveInputEvent = false;
    boolean needSurfaceSizeUpdate = false;
    if (!inputInfo.equals(mInputInfo)) {
        mInputInfo = inputInfo;
        if (DEBUG) {
            Log.d(TAG,
                    "Input \'" + mInputInfo.getId() + "\' can receive input event: " + mCanReceiveInputEvent);
        }
        needSurfaceSizeUpdate = true;
    }
    mChannelViewTimer.start();
    mVideoWidth = 0;
    mVideoHeight = 0;
    mVideoFormat = StreamInfo.VIDEO_DEFINITION_LEVEL_UNKNOWN;
    mVideoFrameRate = 0f;
    mVideoDisplayAspectRatio = 0f;
    mAudioChannelCount = StreamInfo.AUDIO_CHANNEL_COUNT_UNKNOWN;
    mHasClosedCaption = false;
    mTvView.setCallback(mCallback);
    mTimeShiftCurrentPositionMs = INVALID_TIME;
    mTvView.setTimeShiftPositionCallback(null);
    setTimeShiftAvailable(false);
    mTvView.timeShiftPlay(inputId, recordingUri);
    if (needSurfaceSizeUpdate && mFixedSurfaceWidth > 0 && mFixedSurfaceHeight > 0) {
        // When the input is changed, TvView recreates its SurfaceView internally.
        // So we need to call SurfaceHolder.setFixedSize for the new SurfaceView.
        getSurfaceView().getHolder().setFixedSize(mFixedSurfaceWidth, mFixedSurfaceHeight);
    }
    hideScreenByVideoAvailability(TvInputManager.VIDEO_UNAVAILABLE_REASON_TUNING);
    unblockScreenByContentRating();
    if (mParentControlEnabled) {
        mBlockScreenForTuneView.setVisibility(View.VISIBLE);
    }
    if (mOnTuneListener != null) {
        mOnTuneListener.onStreamInfoChanged(this);
    }
    return true;
}

From source file:com.android.tv.ui.TunableTvView.java

/**
 * Tunes to a channel with the {@code channelId}.
 *
 * @param params extra data to send it to TIS and store the data in TIMS.
 * @return false, if the TV input is not a proper state to tune to a channel. For example,
 *         if the state is disconnected or channelId doesn't exist, it returns false.
 *///from www .j a  va2s . c  o m
public boolean tuneTo(Channel channel, Bundle params, OnTuneListener listener) {
    if (!mStarted) {
        throw new IllegalStateException("TvView isn't started");
    }
    if (DEBUG)
        Log.d(TAG, "tuneTo " + channel);
    TvInputInfo inputInfo = mInputManagerHelper.getTvInputInfo(channel.getInputId());
    if (inputInfo == null) {
        return false;
    }
    if (mCurrentChannel != null) {
        long duration = mChannelViewTimer.reset();
        mTracker.sendChannelViewStop(mCurrentChannel, duration);
        if (mWatchedHistoryManager != null && !mCurrentChannel.isPassthrough()) {
            mWatchedHistoryManager.logChannelViewStop(mCurrentChannel, System.currentTimeMillis(), duration);
        }
    }
    mOnTuneListener = listener;
    mCurrentChannel = channel;
    mRecordedProgram = null;
    boolean tunedByRecommendation = params != null
            && params.getString(NotificationService.TUNE_PARAMS_RECOMMENDATION_TYPE) != null;
    boolean needSurfaceSizeUpdate = false;
    if (!inputInfo.equals(mInputInfo)) {
        mInputInfo = inputInfo;
        mCanReceiveInputEvent = getContext().getPackageManager().checkPermission(PERMISSION_RECEIVE_INPUT_EVENT,
                mInputInfo.getServiceInfo().packageName) == PackageManager.PERMISSION_GRANTED;
        if (DEBUG) {
            Log.d(TAG,
                    "Input \'" + mInputInfo.getId() + "\' can receive input event: " + mCanReceiveInputEvent);
        }
        needSurfaceSizeUpdate = true;
    }
    mTracker.sendChannelViewStart(mCurrentChannel, tunedByRecommendation);
    mChannelViewTimer.start();
    mVideoWidth = 0;
    mVideoHeight = 0;
    mVideoFormat = StreamInfo.VIDEO_DEFINITION_LEVEL_UNKNOWN;
    mVideoFrameRate = 0f;
    mVideoDisplayAspectRatio = 0f;
    mAudioChannelCount = StreamInfo.AUDIO_CHANNEL_COUNT_UNKNOWN;
    mHasClosedCaption = false;
    mTvView.setCallback(mCallback);
    mTimeShiftCurrentPositionMs = INVALID_TIME;
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        // To reduce the IPCs, unregister the callback here and register it when necessary.
        mTvView.setTimeShiftPositionCallback(null);
    }
    setTimeShiftAvailable(false);
    mTvView.tune(mInputInfo.getId(), mCurrentChannel.getUri(), params);
    if (needSurfaceSizeUpdate && mFixedSurfaceWidth > 0 && mFixedSurfaceHeight > 0) {
        // When the input is changed, TvView recreates its SurfaceView internally.
        // So we need to call SurfaceHolder.setFixedSize for the new SurfaceView.
        getSurfaceView().getHolder().setFixedSize(mFixedSurfaceWidth, mFixedSurfaceHeight);
    }
    hideScreenByVideoAvailability(TvInputManager.VIDEO_UNAVAILABLE_REASON_TUNING);
    unblockScreenByContentRating();
    if (channel.isPassthrough()) {
        mBlockScreenForTuneView.setVisibility(View.GONE);
    } else if (mParentControlEnabled) {
        mBlockScreenForTuneView.setVisibility(View.VISIBLE);
    }
    if (mOnTuneListener != null) {
        mOnTuneListener.onStreamInfoChanged(this);
    }
    return true;
}

From source file:com.android.tv.ui.TunableTvView.java

@UiThread
private void hideScreenByVideoAvailability(int reason) {
    mVideoAvailable = false;/*from  www.  j a  va 2  s  .  c  om*/
    mVideoUnavailableReason = reason;
    if (mInternetCheckTask != null) {
        mInternetCheckTask.cancel(true);
        mInternetCheckTask = null;
    }
    switch (reason) {
    case TvInputManager.VIDEO_UNAVAILABLE_REASON_AUDIO_ONLY:
        mHideScreenView.setVisibility(VISIBLE);
        mHideScreenView.setImageVisibility(false);
        mHideScreenView.setText(R.string.tvview_msg_audio_only);
        mBufferingSpinnerView.setVisibility(GONE);
        unmuteIfPossible();
        break;
    case TvInputManager.VIDEO_UNAVAILABLE_REASON_BUFFERING:
        mBufferingSpinnerView.setVisibility(VISIBLE);
        mute();
        break;
    case TvInputManager.VIDEO_UNAVAILABLE_REASON_WEAK_SIGNAL:
        mHideScreenView.setVisibility(VISIBLE);
        mHideScreenView.setText(R.string.tvview_msg_weak_signal);
        mBufferingSpinnerView.setVisibility(GONE);
        mute();
        break;
    case TvInputManager.VIDEO_UNAVAILABLE_REASON_TUNING:
    case VIDEO_UNAVAILABLE_REASON_NOT_TUNED:
        mHideScreenView.setVisibility(VISIBLE);
        mHideScreenView.setImageVisibility(false);
        mHideScreenView.setText(null);
        mBufferingSpinnerView.setVisibility(GONE);
        mute();
        break;
    case TvInputManager.VIDEO_UNAVAILABLE_REASON_UNKNOWN:
    default:
        mHideScreenView.setVisibility(VISIBLE);
        mHideScreenView.setImageVisibility(false);
        mHideScreenView.setText(null);
        mBufferingSpinnerView.setVisibility(GONE);
        mute();
        if (mCurrentChannel != null && !mCurrentChannel.isPhysicalTunerChannel()) {
            mInternetCheckTask = new InternetCheckTask();
            mInternetCheckTask.execute();
        }
        break;
    }
}

From source file:com.android.tv.MainActivity.java

private void updateAvailabilityToast(StreamInfo info) {
    if (info.isVideoAvailable()) {
        return;//from  w ww .  j  a v a 2s .  co m
    }

    int stringId;
    switch (info.getVideoUnavailableReason()) {
    case TunableTvView.VIDEO_UNAVAILABLE_REASON_NOT_TUNED:
    case TvInputManager.VIDEO_UNAVAILABLE_REASON_TUNING:
    case TvInputManager.VIDEO_UNAVAILABLE_REASON_BUFFERING:
    case TvInputManager.VIDEO_UNAVAILABLE_REASON_AUDIO_ONLY:
    case TvInputManager.VIDEO_UNAVAILABLE_REASON_WEAK_SIGNAL:
        return;
    case TvInputManager.VIDEO_UNAVAILABLE_REASON_UNKNOWN:
    default:
        stringId = R.string.msg_channel_unavailable_unknown;
        break;
    }

    Toast.makeText(this, stringId, Toast.LENGTH_SHORT).show();
}