android.media.tv.TvInputManager Java Examples

The following examples show how to use android.media.tv.TvInputManager. 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: SimpleSessionImpl.java    From ChannelSurfer with MIT License 6 votes vote down vote up
@Override
    public boolean onTune(Uri channelUri) {
        lastTune = new Date();
        currentChannelUri = channelUri;
//        notifyVideoUnavailable(TvInputManager.VIDEO_UNAVAILABLE_REASON_TUNING);
        if(tvInputProvider instanceof SplashScreenable) {
            notifyVideoAvailable();
            setOverlayViewEnabled(false);
            setOverlayViewEnabled(true);
            isStillLoading = true;
        } else
            notifyVideoUnavailable(TvInputManager.VIDEO_UNAVAILABLE_REASON_BUFFERING);
        setOverlayViewEnabled(true);
        new TuningTask().execute(channelUri, this);
        return true;
    }
 
Example #2
Source File: TestTvInputService.java    From androidtv-sample-inputs with Apache License 2.0 6 votes vote down vote up
private boolean playMediaUrl(String mediaUrl) {
    getTvPlayer();
    Log.d(TAG, "Play " + mediaUrl);
    try {
        if (mediaUrl.startsWith("assets://")) {
            AssetFileDescriptor fileDescriptor = getAssets().openFd(mediaUrl.substring(9));
            mMockTvPlayer.playMediaFromAssets(fileDescriptor);
        } else {
            mMockTvPlayer.playMedia(mediaUrl);
        }
    } catch (IOException e) {
        e.printStackTrace();
        notifyVideoUnavailable(TvInputManager.VIDEO_UNAVAILABLE_REASON_UNKNOWN);
        return false;
    }
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        notifyTimeShiftStatusChanged(TvInputManager.TIME_SHIFT_STATUS_AVAILABLE);
    }
    notifyVideoAvailable();
    return true;
}
 
Example #3
Source File: BaseTvInputService.java    From androidtv-sample-inputs with Apache License 2.0 6 votes vote down vote up
@Override
public void run() {
    ContentResolver resolver = mContext.getContentResolver();
    Program program = null;
    long timeShiftedDifference =
            System.currentTimeMillis() - mTimeShiftedPlaybackPosition;
    if (mTimeShiftedPlaybackPosition != TvInputManager.TIME_SHIFT_INVALID_TIME
            && timeShiftedDifference > TIME_SHIFTED_MINIMUM_DIFFERENCE_MILLIS) {
        program = ModelUtils.getNextProgram(resolver, mChannelUri, mCurrentProgram);
    } else {
        mTimeShiftedPlaybackPosition = TvInputManager.TIME_SHIFT_INVALID_TIME;
        program = ModelUtils.getCurrentProgram(resolver, mChannelUri);
    }
    mHandler.removeMessages(MSG_PLAY_CONTENT);
    mHandler.obtainMessage(MSG_PLAY_CONTENT, program).sendToTarget();
}
 
Example #4
Source File: BaseTvInputService.java    From androidtv-sample-inputs with Apache License 2.0 6 votes vote down vote up
@Override
public TvPlayer onAdReadyToPlay(String adVideoUrl) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        notifyTimeShiftStatusChanged(TvInputManager.TIME_SHIFT_STATUS_UNAVAILABLE);
    }

    onPlayAdvertisement(
            new Advertisement.Builder(mAdvertisement)
                    .setRequestUrl(adVideoUrl)
                    .build());
    setTvPlayerSurface(mSurface);
    setTvPlayerVolume(mVolume);

    long currentTimeMs = System.currentTimeMillis();
    long adStartTime = mAdvertisement.getStartTimeUtcMillis();
    if (adStartTime > 0 && adStartTime < currentTimeMs) {
        getTvPlayer().seekTo(currentTimeMs - adStartTime);
    }
    return getTvPlayer();
}
 
Example #5
Source File: BaseTvInputService.java    From androidtv-sample-inputs with Apache License 2.0 6 votes vote down vote up
@Override
public boolean onTune(Uri channelUri) {
    mNeedToCheckChannelAd = true;

    notifyVideoUnavailable(TvInputManager.VIDEO_UNAVAILABLE_REASON_TUNING);

    mChannelUri = channelUri;
    long channelId = ContentUris.parseId(channelUri);
    mCurrentChannel = mChannelMap.get(channelId);

    mTimeShiftedPlaybackPosition = TvInputManager.TIME_SHIFT_INVALID_TIME;

    // Release Ads assets
    releaseAdController();
    mHandler.removeMessages(MSG_PLAY_AD);

    if (mDbHandler != null) {
        mUnblockedRatingSet.clear();
        mDbHandler.removeCallbacks(mGetCurrentProgramRunnable);
        mGetCurrentProgramRunnable = new GetCurrentProgramRunnable(mChannelUri);
        mDbHandler.post(mGetCurrentProgramRunnable);
    }
    return true;
}
 
Example #6
Source File: RichTvInputService.java    From androidtv-sample-inputs with Apache License 2.0 6 votes vote down vote up
@Override
public void onStateChanged(boolean playWhenReady, int playbackState) {
    if (mPlayer == null) {
        return;
    }

    if (playWhenReady && playbackState == ExoPlayer.STATE_READY) {
        notifyTracksChanged(getAllTracks());
        String audioId = getTrackId(TvTrackInfo.TYPE_AUDIO,
                mPlayer.getSelectedTrack(TvTrackInfo.TYPE_AUDIO));
        String videoId = getTrackId(TvTrackInfo.TYPE_VIDEO,
                mPlayer.getSelectedTrack(TvTrackInfo.TYPE_VIDEO));
        String textId = getTrackId(TvTrackInfo.TYPE_SUBTITLE,
                mPlayer.getSelectedTrack(TvTrackInfo.TYPE_SUBTITLE));

        notifyTrackSelected(TvTrackInfo.TYPE_AUDIO, audioId);
        notifyTrackSelected(TvTrackInfo.TYPE_VIDEO, videoId);
        notifyTrackSelected(TvTrackInfo.TYPE_SUBTITLE, textId);
        notifyVideoAvailable();
    } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M &&
            Math.abs(mPlayer.getPlaybackSpeed() - 1) < 0.1 &&
            playWhenReady && playbackState == ExoPlayer.STATE_BUFFERING) {
        notifyVideoUnavailable(TvInputManager.VIDEO_UNAVAILABLE_REASON_BUFFERING);
    }
}
 
Example #7
Source File: RichTvInputService.java    From androidtv-sample-inputs with Apache License 2.0 6 votes vote down vote up
@Override
public boolean onPlayProgram(Program program, long startPosMs) {
    if (program == null) {
        requestEpgSync(getCurrentChannelUri());
        notifyVideoUnavailable(TvInputManager.VIDEO_UNAVAILABLE_REASON_TUNING);
        return false;
    }
    createPlayer(program.getInternalProviderData().getVideoType(),
            Uri.parse(program.getInternalProviderData().getVideoUrl()));
    if (startPosMs > 0) {
        mPlayer.seekTo(startPosMs);
    }
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        notifyTimeShiftStatusChanged(TvInputManager.TIME_SHIFT_STATUS_AVAILABLE);
    }
    mPlayer.setPlayWhenReady(true);
    return true;
}
 
Example #8
Source File: ProviderTvInputService.java    From xipl with Apache License 2.0 6 votes vote down vote up
@Override
public void onPlayChannel(Channel channel) {
    if (channel.getInternalProviderData() !=  null) {
        mProviderTvPlayer = new ProviderTvPlayer(mContext, channel.getInternalProviderData().getVideoUrl());
        mProviderTvPlayer.addListener(this);

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            notifyTimeShiftStatusChanged(TvInputManager.TIME_SHIFT_STATUS_UNSUPPORTED);
        }

        if (DEBUG) {
            Log.d(getClass().getSimpleName(), "Video Url: " + channel.getInternalProviderData().getVideoUrl());
            Log.d(getClass().getSimpleName(), "Video format: " + channel.getVideoFormat());
        }

        // Notify when the video is available so the channel surface can be shown to the screen.
        mProviderTvPlayer.play();
    } else {
        Toast.makeText(mContext, R.string.channel_stream_failure, Toast.LENGTH_SHORT).show();
    }
}
 
Example #9
Source File: TestTvInputService.java    From xipl with Apache License 2.0 6 votes vote down vote up
private boolean playMediaUrl(String mediaUrl) {
    getTvPlayer();
    Log.d(TAG, "Play " + mediaUrl);
    try {
        if (mediaUrl.startsWith("assets://")) {
            AssetFileDescriptor fileDescriptor = getAssets().openFd(mediaUrl.substring(9));
            mMockTvPlayer.playMediaFromAssets(fileDescriptor);
        } else {
            mMockTvPlayer.playMedia(mediaUrl);
        }
    } catch (IOException e) {
        e.printStackTrace();
        notifyVideoUnavailable(TvInputManager.VIDEO_UNAVAILABLE_REASON_UNKNOWN);
        return false;
    }
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        notifyTimeShiftStatusChanged(TvInputManager.TIME_SHIFT_STATUS_AVAILABLE);
    }
    notifyVideoAvailable();
    return true;
}
 
Example #10
Source File: BaseTvInputService.java    From xipl with Apache License 2.0 6 votes vote down vote up
@Override
public void run() {
    ContentResolver resolver = mContext.getContentResolver();
    Program program = null;
    long timeShiftedDifference =
            System.currentTimeMillis() - mTimeShiftedPlaybackPosition;
    if (mTimeShiftedPlaybackPosition != TvInputManager.TIME_SHIFT_INVALID_TIME
            && timeShiftedDifference > TIME_SHIFTED_MINIMUM_DIFFERENCE_MILLIS) {
        program = ModelUtils.getNextProgram(resolver, mChannelUri, mCurrentProgram);
    } else {
        mTimeShiftedPlaybackPosition = TvInputManager.TIME_SHIFT_INVALID_TIME;
        program = ModelUtils.getCurrentProgram(resolver, mChannelUri);
    }
    mHandler.removeMessages(MSG_PLAY_CONTENT);
    mHandler.obtainMessage(MSG_PLAY_CONTENT, program).sendToTarget();
}
 
Example #11
Source File: BaseTvInputService.java    From xipl with Apache License 2.0 6 votes vote down vote up
@Override
public TvPlayer onAdReadyToPlay(String adVideoUrl) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        notifyTimeShiftStatusChanged(TvInputManager.TIME_SHIFT_STATUS_UNAVAILABLE);
    }

    onPlayAdvertisement(
            new Advertisement.Builder(mAdvertisement)
                    .setRequestUrl(adVideoUrl)
                    .build());
    setTvPlayerSurface(mSurface);
    setTvPlayerVolume(mVolume);

    long currentTimeMs = System.currentTimeMillis();
    long adStartTime = mAdvertisement.getStartTimeUtcMillis();
    if (adStartTime > 0 && adStartTime < currentTimeMs) {
        getTvPlayer().seekTo(currentTimeMs - adStartTime);
    }
    return getTvPlayer();
}
 
Example #12
Source File: BaseTvInputService.java    From xipl with Apache License 2.0 6 votes vote down vote up
@Override
public void onCreate() {
    super.onCreate();
    // Create background thread
    mDbHandlerThread = new HandlerThread(getClass().getSimpleName());
    mDbHandlerThread.start();

    // Initialize the channel map and set observer for changes
    mContentResolver = BaseTvInputService.this.getContentResolver();
    updateChannelMap();
    mChannelObserver =
            new ContentObserver(new Handler(mDbHandlerThread.getLooper())) {
                @Override
                public void onChange(boolean selfChange) {
                    updateChannelMap();
                }
            };
    mContentResolver.registerContentObserver(
            TvContract.Channels.CONTENT_URI, true, mChannelObserver);

    // Setup our BroadcastReceiver
    IntentFilter intentFilter = new IntentFilter();
    intentFilter.addAction(TvInputManager.ACTION_BLOCKED_RATINGS_CHANGED);
    intentFilter.addAction(TvInputManager.ACTION_PARENTAL_CONTROLS_ENABLED_CHANGED);
    registerReceiver(mParentalControlsBroadcastReceiver, intentFilter);
}
 
Example #13
Source File: PreviewVideoInputService.java    From leanback-homescreen-channels with Apache License 2.0 6 votes vote down vote up
PreviewSession(Context context) {
    super(context);
    mPlayer = new MediaPlayer();

    mGetClipByIdListener = new GetClipByIdListener() {
        @Override
        public void onGetClipById(Clip clip) {
            try {
                mPlayer.setDataSource(clip.getPreviewVideoUrl());
                mPlayer.prepare();
                mPlayer.start();

                notifyVideoAvailable();
            } catch (IOException e) {
                Log.e(TAG, "Could not prepare media mPlayer", e);
                notifyVideoUnavailable(TvInputManager.VIDEO_UNAVAILABLE_REASON_UNKNOWN);
            }
        }
    };
}
 
Example #14
Source File: TvInputManagerService.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
private void buildTvContentRatingSystemListLocked(int userId) {
    UserState userState = getOrCreateUserStateLocked(userId);
    userState.contentRatingSystemList.clear();

    final PackageManager pm = mContext.getPackageManager();
    Intent intent = new Intent(TvInputManager.ACTION_QUERY_CONTENT_RATING_SYSTEMS);
    for (ResolveInfo resolveInfo :
            pm.queryBroadcastReceivers(intent, PackageManager.GET_META_DATA)) {
        ActivityInfo receiver = resolveInfo.activityInfo;
        Bundle metaData = receiver.metaData;
        if (metaData == null) {
            continue;
        }

        int xmlResId = metaData.getInt(TvInputManager.META_DATA_CONTENT_RATING_SYSTEMS);
        if (xmlResId == 0) {
            Slog.w(TAG, "Missing meta-data '"
                    + TvInputManager.META_DATA_CONTENT_RATING_SYSTEMS + "' on receiver "
                    + receiver.packageName + "/" + receiver.name);
            continue;
        }
        userState.contentRatingSystemList.add(
                TvContentRatingSystemInfo.createTvContentRatingSystemInfo(xmlResId,
                        receiver.applicationInfo));
    }
}
 
Example #15
Source File: BaseTvInputService.java    From androidtv-sample-inputs with Apache License 2.0 5 votes vote down vote up
@Override
public void onReceive(Context context, Intent intent) {
    for (Session session : mSessions) {
        TvInputManager manager =
                (TvInputManager) context.getSystemService(Context.TV_INPUT_SERVICE);

        if (!manager.isParentalControlsEnabled()) {
            session.onUnblockContent(null);
        } else {
            session.checkCurrentProgramContent();
        }
    }
}
 
Example #16
Source File: CumulusTvTifService.java    From CumulusTV with MIT License 5 votes vote down vote up
@TargetApi(Build.VERSION_CODES.M)
@RequiresApi(api = Build.VERSION_CODES.M)
@Override
public long onTimeShiftGetCurrentPosition() {
    if (mPlayer == null) {
        return TvInputManager.TIME_SHIFT_INVALID_TIME;
    }
    long currentMs = tuneTime + mPlayer.getCurrentPosition();
    if (DEBUG) {
        Log.d(TAG, currentMs + "  " + onTimeShiftGetStartPosition() + " start position");
        Log.d(TAG, (currentMs - onTimeShiftGetStartPosition()) + " diff start position");
    }
    return currentMs;
}
 
Example #17
Source File: CumulusTvTifService.java    From CumulusTV with MIT License 5 votes vote down vote up
@Override
public boolean onPlayProgram(Program program, long startPosMs) {
    if (program == null) {
        requestEpgSync(getCurrentChannelUri());
        notifyVideoUnavailable(TvInputManager.VIDEO_UNAVAILABLE_REASON_TUNING);
        return false;
    }
    jsonChannel = ChannelDatabase.getInstance(getApplicationContext()).findChannelByMediaUrl(
            program.getInternalProviderData().getVideoUrl());
    Log.d(TAG, "Play program " + program.getTitle() + " " +
            program.getInternalProviderData().getVideoUrl());
    if (program.getInternalProviderData().getVideoUrl() == null) {
        Toast.makeText(mContext, getString(R.string.msg_no_url_found), Toast.LENGTH_SHORT).show();
        notifyVideoUnavailable(TvInputManager.VIDEO_UNAVAILABLE_REASON_UNKNOWN);
        return false;
    } else {
        createPlayer(program.getInternalProviderData().getVideoType(),
                Uri.parse(program.getInternalProviderData().getVideoUrl()));
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            notifyTimeShiftStatusChanged(TvInputManager.TIME_SHIFT_STATUS_AVAILABLE);
        }
        mPlayer.play();
        notifyVideoAvailable();
        Log.d(TAG, "The video should start playing");
        return true;
    }
}
 
Example #18
Source File: CumulusTvTifService.java    From CumulusTV with MIT License 5 votes vote down vote up
@RequiresApi(api = Build.VERSION_CODES.N)
public boolean onPlayRecordedProgram(RecordedProgram recordedProgram) {
    createPlayer(recordedProgram.getInternalProviderData().getVideoType(),
            Uri.parse(recordedProgram.getInternalProviderData().getVideoUrl()));

    long recordingStartTime = recordedProgram.getInternalProviderData()
            .getRecordedProgramStartTime();
    mPlayer.seekTo(recordingStartTime - recordedProgram.getStartTimeUtcMillis());
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        notifyTimeShiftStatusChanged(TvInputManager.TIME_SHIFT_STATUS_AVAILABLE);
    }
    mPlayer.play();
    notifyVideoAvailable();
    return true;
}
 
Example #19
Source File: CumulusTvTifService.java    From CumulusTV with MIT License 5 votes vote down vote up
@Override
public boolean onTune(Uri channelUri) {
    if (DEBUG) {
        Log.d(TAG, "Tune to " + channelUri.toString());
    }
    notifyVideoUnavailable(TvInputManager.VIDEO_UNAVAILABLE_REASON_TUNING);
    releasePlayer();
    tuneTime = System.currentTimeMillis();
    stillTuning = true;

    // Update our channel
    if (ChannelDatabase.getInstance(mContext).getHashMap() == null) {
        notifyVideoUnavailable(TvInputManager.VIDEO_UNAVAILABLE_REASON_UNKNOWN);
        Toast.makeText(mContext, "Channel HashMap is null", Toast.LENGTH_SHORT).show();
        return false;
    }
    for (String mediaUrl : ChannelDatabase.getInstance(mContext).getHashMap().keySet()) {
        if (channelUri == null) {
            Toast.makeText(mContext, "channelUri is null", Toast.LENGTH_SHORT).show();
            return false;
        }
        if (ChannelDatabase.getInstance(mContext).getHashMap().get(mediaUrl) ==
                Long.parseLong(channelUri.getLastPathSegment())) {
            jsonChannel = ChannelDatabase.getInstance(mContext)
                    .findChannelByMediaUrl(mediaUrl);
        }
    }
    notifyVideoAvailable();
    setOverlayViewEnabled(false);
    setOverlayViewEnabled(true);
    return super.onTune(channelUri);
}
 
Example #20
Source File: RichTvInputService.java    From androidtv-sample-inputs with Apache License 2.0 5 votes vote down vote up
@RequiresApi(api = Build.VERSION_CODES.N)
public boolean onPlayRecordedProgram(RecordedProgram recordedProgram) {
    createPlayer(recordedProgram.getInternalProviderData().getVideoType(),
            Uri.parse(recordedProgram.getInternalProviderData().getVideoUrl()));

    long recordingStartTime = recordedProgram.getInternalProviderData()
            .getRecordedProgramStartTime();
    mPlayer.seekTo(recordingStartTime - recordedProgram.getStartTimeUtcMillis());
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        notifyTimeShiftStatusChanged(TvInputManager.TIME_SHIFT_STATUS_AVAILABLE);
    }
    mPlayer.setPlayWhenReady(true);
    return true;
}
 
Example #21
Source File: RichTvInputService.java    From androidtv-sample-inputs with Apache License 2.0 5 votes vote down vote up
@Override
public boolean onTune(Uri channelUri) {
    if (DEBUG) {
        Log.d(TAG, "Tune to " + channelUri.toString());
    }
    notifyVideoUnavailable(TvInputManager.VIDEO_UNAVAILABLE_REASON_TUNING);
    releasePlayer();
    return super.onTune(channelUri);
}
 
Example #22
Source File: HdmiControlService.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
@Override
public void onBootPhase(int phase) {
    if (phase == SystemService.PHASE_SYSTEM_SERVICES_READY) {
        mTvInputManager = (TvInputManager) getContext().getSystemService(
                Context.TV_INPUT_SERVICE);
        mPowerManager = (PowerManager) getContext().getSystemService(Context.POWER_SERVICE);
    }
}
 
Example #23
Source File: RichTvInputService.java    From androidtv-sample-inputs with Apache License 2.0 5 votes vote down vote up
@Override
public void onStopRecordingChannel(Channel channelToRecord) {
    if (DEBUG) {
        Log.d(TAG, "onStopRecording");
    }
    // Program sources in this sample always include program info, so execution here
    // indicates an error.
    notifyError(TvInputManager.RECORDING_ERROR_UNKNOWN);
    return;
}
 
Example #24
Source File: BaseTvInputService.java    From androidtv-sample-inputs with Apache License 2.0 5 votes vote down vote up
@Override
public void run() {
    ContentResolver contentResolver = mContext.getContentResolver();
    Cursor cursor =
            contentResolver.query(
                    mRecordedProgramUri, RecordedProgram.PROJECTION, null, null, null);
    if (cursor == null) {
        // The recorded program does not exist.
        notifyVideoUnavailable(TvInputManager.VIDEO_UNAVAILABLE_REASON_UNKNOWN);
    } else {
        if (cursor.moveToNext()) {
            RecordedProgram recordedProgram = RecordedProgram.fromCursor(cursor);
            if (DEBUG) {
                Log.d(TAG, "Play program " + recordedProgram.getTitle());
                Log.d(TAG, recordedProgram.getRecordingDataUri());
            }
            if (recordedProgram == null) {
                Log.e(
                        TAG,
                        "RecordedProgram at "
                                + mRecordedProgramUri
                                + " does not "
                                + "exist");
                notifyVideoUnavailable(TvInputManager.VIDEO_UNAVAILABLE_REASON_UNKNOWN);
            }
            mHandler.removeMessages(MSG_PLAY_RECORDED_CONTENT);
            mHandler.obtainMessage(MSG_PLAY_RECORDED_CONTENT, recordedProgram)
                    .sendToTarget();
        }
    }
}
 
Example #25
Source File: BaseTvInputService.java    From androidtv-sample-inputs with Apache License 2.0 5 votes vote down vote up
@Override
public void onCreate() {
    super.onCreate();
    // Create background thread
    mDbHandlerThread = new HandlerThread(getClass().getSimpleName());
    mDbHandlerThread.start();

    // Initialize the channel map and set observer for changes
    mContentResolver = BaseTvInputService.this.getContentResolver();
    updateChannelMap();
    mChannelObserver =
            new ContentObserver(new Handler(mDbHandlerThread.getLooper())) {
                @Override
                public void onChange(boolean selfChange) {
                    updateChannelMap();
                }
            };
    mContentResolver.registerContentObserver(
            TvContract.Channels.CONTENT_URI, true, mChannelObserver);

    // Setup our BroadcastReceiver
    IntentFilter intentFilter = new IntentFilter();
    intentFilter.addAction(TvInputManager.ACTION_BLOCKED_RATINGS_CHANGED);
    intentFilter.addAction(TvInputManager.ACTION_PARENTAL_CONTROLS_ENABLED_CHANGED);
    registerReceiver(mParentalControlsBroadcastReceiver, intentFilter);
}
 
Example #26
Source File: BaseTvInputService.java    From xipl with Apache License 2.0 5 votes vote down vote up
public Session(Context context, String inputId) {
    super(context);
    this.mContext = context;
    mTvInputManager = (TvInputManager) context.getSystemService(Context.TV_INPUT_SERVICE);
    mLastBlockedRating = null;
    mDbHandler = new Handler(mDbHandlerThread.getLooper());
    mHandler = new Handler(this);
}
 
Example #27
Source File: BaseTvInputService.java    From androidtv-sample-inputs with Apache License 2.0 5 votes vote down vote up
public Session(Context context, String inputId) {
    super(context);
    this.mContext = context;
    mTvInputManager = (TvInputManager) context.getSystemService(Context.TV_INPUT_SERVICE);
    mLastBlockedRating = null;
    mDbHandler = new Handler(mDbHandlerThread.getLooper());
    mHandler = new Handler(this);
}
 
Example #28
Source File: PersistentDataStore.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
private void broadcastChangesIfNeeded() {
    if (mParentalControlsEnabledChanged) {
        mParentalControlsEnabledChanged = false;
        mContext.sendBroadcastAsUser(new Intent(
                TvInputManager.ACTION_PARENTAL_CONTROLS_ENABLED_CHANGED), UserHandle.ALL);
    }
    if (mBlockedRatingsChanged) {
        mBlockedRatingsChanged = false;
        mContext.sendBroadcastAsUser(new Intent(TvInputManager.ACTION_BLOCKED_RATINGS_CHANGED),
                UserHandle.ALL);
    }
}
 
Example #29
Source File: BaseTvInputService.java    From androidtv-sample-inputs with Apache License 2.0 5 votes vote down vote up
@RequiresApi(api = Build.VERSION_CODES.M)
@Override
public long onTimeShiftGetStartPosition() {
    if (mCurrentProgram != null) {
        if (mPlayingRecordedProgram) {
            return mRecordedPlaybackStartTime;
        } else {
            return mCurrentProgram.getStartTimeUtcMillis();
        }
    }
    return TvInputManager.TIME_SHIFT_INVALID_TIME;
}
 
Example #30
Source File: BaseTvInputService.java    From androidtv-sample-inputs with Apache License 2.0 5 votes vote down vote up
private long getCurrentTime() {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        long timeShiftedDifference =
                System.currentTimeMillis() - mTimeShiftedPlaybackPosition;
        if (mTimeShiftedPlaybackPosition != TvInputManager.TIME_SHIFT_INVALID_TIME
                && timeShiftedDifference > TIME_SHIFTED_MINIMUM_DIFFERENCE_MILLIS) {
            return mTimeShiftedPlaybackPosition;
        }
    }
    mTimeShiftedPlaybackPosition = TvInputManager.TIME_SHIFT_INVALID_TIME;
    return System.currentTimeMillis();
}