android.media.tv.TvTrackInfo Java Examples
The following examples show how to use
android.media.tv.TvTrackInfo.
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: TvInputManagerService.java From android_9.0.0_r45 with Apache License 2.0 | 6 votes |
@Override public void onTracksChanged(List<TvTrackInfo> tracks) { synchronized (mLock) { if (DEBUG) { Slog.d(TAG, "onTracksChanged(" + tracks + ")"); } if (mSessionState.session == null || mSessionState.client == null) { return; } try { mSessionState.client.onTracksChanged(tracks, mSessionState.seq); } catch (RemoteException e) { Slog.e(TAG, "error in onTracksChanged", e); } } }
Example #2
Source File: RichTvInputService.java From androidtv-sample-inputs with Apache License 2.0 | 6 votes |
@Override public boolean onSelectTrack(int type, String trackId) { if (trackId == null) { return true; } int trackIndex = getIndexFromTrackId(trackId); if (mPlayer != null) { if (type == TvTrackInfo.TYPE_SUBTITLE) { if (! mCaptionEnabled) { return false; } mSelectedSubtitleTrackIndex = trackIndex; } mPlayer.setSelectedTrack(type, trackIndex); notifyTrackSelected(type, trackId); return true; } return false; }
Example #3
Source File: RichTvInputService.java From androidtv-sample-inputs with Apache License 2.0 | 6 votes |
@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 #4
Source File: ProviderTvInputService.java From xipl with Apache License 2.0 | 5 votes |
@Override public void onPlayerStateChanged(boolean playWhenReady, int playbackState) { if (playWhenReady && playbackState == Player.STATE_READY) { notifyTracksChanged(getAllTracks()); notifyTrackSelected(TvTrackInfo.TYPE_VIDEO, getTrackId(TvTrackInfo.TYPE_VIDEO)); notifyTrackSelected(TvTrackInfo.TYPE_AUDIO, getTrackId(TvTrackInfo.TYPE_AUDIO)); notifyVideoAvailable(); } if (DEBUG) { Log.d(getClass().getSimpleName(), "Player state changed to " + playbackState + ", PWR: " + playWhenReady); } }
Example #5
Source File: ProviderTvInputService.java From xipl with Apache License 2.0 | 5 votes |
/** * Gives the id for a given track based on it's type between {@link TvTrackInfo#TYPE_VIDEO} * or {@link TvTrackInfo#TYPE_AUDIO} * * @param trackType The track type of the stream * @return the default track id used for the stream. */ private String getTrackId(int trackType) { /* Android versions before Nougat, each track has a global unique id that can't be used for different track types. */ if ((trackType == TvTrackInfo.TYPE_VIDEO || trackType == TvTrackInfo.TYPE_AUDIO) && Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { return (Integer.toString(0)); } else { return (Integer.toString(trackType)); } }
Example #6
Source File: RichTvInputService.java From androidtv-sample-inputs with Apache License 2.0 | 5 votes |
@Override public void onSetCaptionEnabled(boolean enabled) { mCaptionEnabled = enabled; if (mPlayer != null) { if (mCaptionEnabled) { mPlayer.setSelectedTrack(TvTrackInfo.TYPE_SUBTITLE, mSelectedSubtitleTrackIndex); } else { mPlayer.setSelectedTrack(TvTrackInfo.TYPE_SUBTITLE, DemoPlayer.TRACK_DISABLED); } } }
Example #7
Source File: ProviderTvInputService.java From xipl with Apache License 2.0 | 4 votes |
/** * Returns a given track based on the player's video or audio format. * * @param trackType the type as defined by {@link TvTrackInfo#TYPE_VIDEO} or {@link TvTrackInfo#TYPE_AUDIO} * @return the related {@link TvTrackInfo} for a given player track. */ private TvTrackInfo getTrack(int trackType) { /* Note that we should allow for multiple tracks. However, since this is a TV stream, it most likely consists of one video, one audio and one subtitle track. We're skipping the subtitle track since it gets mostly delayed and might not offer the best experience. It might get added in the future. */ Format format = null; TvTrackInfo.Builder builder; // Versions before Nougat expects a general TvTrackInfo id and not one based on the type. if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { builder = new TvTrackInfo.Builder(trackType, Integer.toString(0)); } else { builder = new TvTrackInfo.Builder(trackType, Integer.toString(trackType)); } if (trackType == TvTrackInfo.TYPE_VIDEO) { format = mProviderTvPlayer.getVideoFormat(); } else if (trackType == TvTrackInfo.TYPE_AUDIO) { format = mProviderTvPlayer.getAudioFormat(); } if (format != null) { if (trackType == TvTrackInfo.TYPE_VIDEO) { if (format.width != Format.NO_VALUE) { builder.setVideoWidth(format.width); } if (format.height != Format.NO_VALUE) { builder.setVideoHeight(format.height); } } else { builder.setAudioChannelCount(format.channelCount); builder.setAudioSampleRate(format.sampleRate); } } return (builder.build()); }
Example #8
Source File: TvInputPlayer.java From ChannelSurfer with MIT License | 4 votes |
public TvTrackInfo[] getTracks(int trackType) { if (trackType < 0 || trackType >= mTvTracks.length) { throw new IllegalArgumentException("Illegal track type: " + trackType); } return mTvTracks[trackType]; }
Example #9
Source File: RichTvInputService.java From androidtv-sample-inputs with Apache License 2.0 | 4 votes |
private List<TvTrackInfo> getAllTracks() { String trackId; List<TvTrackInfo> tracks = new ArrayList<>(); int[] trackTypes = { DemoPlayer.TYPE_AUDIO, DemoPlayer.TYPE_VIDEO, DemoPlayer.TYPE_TEXT }; for (int trackType : trackTypes) { int count = mPlayer.getTrackCount(trackType); for (int i = 0; i < count; i++) { MediaFormat format = mPlayer.getTrackFormat(trackType, i); trackId = getTrackId(trackType, i); TvTrackInfo.Builder builder = new TvTrackInfo.Builder(trackType, trackId); if (trackType == DemoPlayer.TYPE_VIDEO) { if (format.maxWidth != MediaFormat.NO_VALUE) { builder.setVideoWidth(format.maxWidth); } else if (format.width != MediaFormat.NO_VALUE) { builder.setVideoWidth(format.width); } if (format.maxHeight != MediaFormat.NO_VALUE) { builder.setVideoHeight(format.maxHeight); } else if (format.height != MediaFormat.NO_VALUE) { builder.setVideoHeight(format.height); } } else if (trackType == DemoPlayer.TYPE_AUDIO) { builder.setAudioChannelCount(format.channelCount); builder.setAudioSampleRate(format.sampleRate); if (format.language != null && !UNKNOWN_LANGUAGE.equals(format.language)) { // TvInputInfo expects {@code null} for unknown language. builder.setLanguage(format.language); } } else if (trackType == DemoPlayer.TYPE_TEXT) { if (format.language != null && !UNKNOWN_LANGUAGE.equals(format.language)) { // TvInputInfo expects {@code null} for unknown language. builder.setLanguage(format.language); } } tracks.add(builder.build()); } } return tracks; }
Example #10
Source File: ProviderTvInputService.java From xipl with Apache License 2.0 | 3 votes |
/** * Gets a list of given tracks for a given channel, whether it is video or audio. * <p> * This way, it is possible for a user to see in the Live Channels application the video * resolution and the audio layout. * * @return the track list usable by the Live Channels application */ private List<TvTrackInfo> getAllTracks() { List<TvTrackInfo> tracks = new ArrayList<>(); tracks.add(getTrack(TvTrackInfo.TYPE_VIDEO)); tracks.add(getTrack(TvTrackInfo.TYPE_AUDIO)); return (tracks); }