com.google.android.exoplayer.ExoPlayer Java Examples
The following examples show how to use
com.google.android.exoplayer.ExoPlayer.
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: EventLogger.java From AndroidTvDemo with Apache License 2.0 | 6 votes |
private String getStateString(int state) { switch (state) { case ExoPlayer.STATE_BUFFERING: return "B"; case ExoPlayer.STATE_ENDED: return "E"; case ExoPlayer.STATE_IDLE: return "I"; case ExoPlayer.STATE_PREPARING: return "P"; case ExoPlayer.STATE_READY: return "R"; default: return "?"; } }
Example #2
Source File: PlayerActivity.java From android-tv-leanback with Apache License 2.0 | 6 votes |
private void preparePlayer() { SampleSource sampleSource = new FrameworkSampleSource(this, Uri.parse(mVideo.getContentUrl()), /* headers */ null, RENDERER_COUNT); // Build the track renderers videoRenderer = new MediaCodecVideoTrackRenderer(sampleSource, MediaCodec.VIDEO_SCALING_MODE_SCALE_TO_FIT); TrackRenderer audioRenderer = new MediaCodecAudioTrackRenderer(sampleSource); // Setup the player player = ExoPlayer.Factory.newInstance(RENDERER_COUNT, 1000, 5000); player.addListener(this); // Build the player controls mediaController.setMediaPlayer(new PlayerControl(player)); mediaController.setEnabled(true); player.prepare(videoRenderer, audioRenderer); }
Example #3
Source File: DemoPlayer.java From Exoplayer_VLC with Apache License 2.0 | 6 votes |
public DemoPlayer(RendererBuilder rendererBuilder) { this.rendererBuilder = rendererBuilder; //###AXT:: --> try to start the player without internal buffering. We do buffering in Raw Sample sources // player = ExoPlayer.Factory.newInstance(RENDERER_COUNT, 1000, 5000); player = ExoPlayer.Factory.newInstance(RENDERER_COUNT, -1, -1); //###AXT:: <-- player.addListener(this); playerControl = new PlayerControl(player); mainHandler = new Handler(); listeners = new CopyOnWriteArrayList<Listener>(); lastReportedPlaybackState = STATE_IDLE; rendererBuildingState = RENDERER_BUILDING_STATE_IDLE; selectedTracks = new int[RENDERER_COUNT]; // Disable text initially. selectedTracks[TYPE_TEXT] = DISABLED_TRACK; }
Example #4
Source File: PlayerActivity.java From android-tv-leanback with Apache License 2.0 | 6 votes |
private void preparePlayer() { SampleSource sampleSource = new FrameworkSampleSource(this, Uri.parse(mVideo.getContentUrl()), /* headers */ null, RENDERER_COUNT); // Build the track renderers videoRenderer = new MediaCodecVideoTrackRenderer(sampleSource, MediaCodec.VIDEO_SCALING_MODE_SCALE_TO_FIT); TrackRenderer audioRenderer = new MediaCodecAudioTrackRenderer(sampleSource); // Setup the player player = ExoPlayer.Factory.newInstance(RENDERER_COUNT, 1000, 5000); player.addListener(this); // Build the player controls mediaController.setMediaPlayer(new PlayerControl(player)); mediaController.setEnabled(true); player.prepare(videoRenderer, audioRenderer); }
Example #5
Source File: EventLogger.java From Exoplayer_VLC with Apache License 2.0 | 6 votes |
private String getStateString(int state) { switch (state) { case ExoPlayer.STATE_BUFFERING: return "B"; case ExoPlayer.STATE_ENDED: return "E"; case ExoPlayer.STATE_IDLE: return "I"; case ExoPlayer.STATE_PREPARING: return "P"; case ExoPlayer.STATE_READY: return "R"; default: return "?"; } }
Example #6
Source File: DurationLogger.java From iview-android-tv with MIT License | 6 votes |
@Override public void onStateChanged(boolean playWhenReady, int playbackState) { state = playbackState; String text = "playWhenReady=" + playWhenReady + ", playbackState="; switch (playbackState) { case ExoPlayer.STATE_BUFFERING: text += "buffering"; break; case ExoPlayer.STATE_ENDED: text += "ended"; break; case ExoPlayer.STATE_IDLE: text += "idle"; break; case ExoPlayer.STATE_PREPARING: text += "preparing"; break; case ExoPlayer.STATE_READY: text += "ready"; break; default: text += "unknown"; break; } Log.d(TAG, text); }
Example #7
Source File: PlayerActivity.java From android-tv-leanback with Apache License 2.0 | 6 votes |
private void preparePlayer() { SampleSource sampleSource = new FrameworkSampleSource(this, Uri.parse(mVideo.getContentUrl()), /* headers */ null, RENDERER_COUNT); // Build the track renderers videoRenderer = new MediaCodecVideoTrackRenderer(sampleSource, MediaCodec.VIDEO_SCALING_MODE_SCALE_TO_FIT); TrackRenderer audioRenderer = new MediaCodecAudioTrackRenderer(sampleSource); // Setup the player player = ExoPlayer.Factory.newInstance(RENDERER_COUNT, 1000, 5000); player.addListener(this); // Build the player controls mediaController.setMediaPlayer(new PlayerControl(player)); mediaController.setEnabled(true); player.prepare(videoRenderer, audioRenderer); }
Example #8
Source File: DurationLogger.java From iview-android-tv with MIT License | 6 votes |
private void executeListeners() { long duration = player.getDuration() / 1000; long position = player.getCurrentPosition() / 1000; List<Pair<Long, OnTimeReached>> executed = new ArrayList<>(); if (duration > 0 && (state == ExoPlayer.STATE_READY || state == ExoPlayer.STATE_ENDED)) { long remain = duration - position; for (Pair<Long, OnTimeReached> listener : listeners) { long condition = listener.first; if (remain <= condition) { Log.d(TAG, "Executing listener, duration=" + duration + ", position=" + position + ", remaining=" + remain); listener.second.onPositionRemainingReached(duration, position); executed.add(listener); } } } listeners.removeAll(executed); }
Example #9
Source File: EventLogger.java From Android-Example-HLS-ExoPlayer with Apache License 2.0 | 6 votes |
private String getStateString(int state) { switch (state) { case ExoPlayer.STATE_BUFFERING: return "B"; case ExoPlayer.STATE_ENDED: return "E"; case ExoPlayer.STATE_IDLE: return "I"; case ExoPlayer.STATE_PREPARING: return "P"; case ExoPlayer.STATE_READY: return "R"; default: return "?"; } }
Example #10
Source File: EventLogger.java From Mobilyzer with Apache License 2.0 | 6 votes |
private String getStateString(int state) { switch (state) { case ExoPlayer.STATE_BUFFERING: return "B"; case ExoPlayer.STATE_ENDED: return "E"; case ExoPlayer.STATE_IDLE: return "I"; case ExoPlayer.STATE_PREPARING: return "P"; case ExoPlayer.STATE_READY: return "R"; default: return "?"; } }
Example #11
Source File: IjkExoMediaPlayer.java From WliveTV with Apache License 2.0 | 6 votes |
@Override public boolean isPlaying() { if (mInternalPlayer == null) return false; int state = mInternalPlayer.getPlaybackState(); switch (state) { case ExoPlayer.STATE_BUFFERING: case ExoPlayer.STATE_READY: return mInternalPlayer.getPlayWhenReady(); case ExoPlayer.STATE_IDLE: case ExoPlayer.STATE_PREPARING: case ExoPlayer.STATE_ENDED: default: return false; } }
Example #12
Source File: EventLogger.java From WliveTV with Apache License 2.0 | 6 votes |
private String getStateString(int state) { switch (state) { case ExoPlayer.STATE_BUFFERING: return "B"; case ExoPlayer.STATE_ENDED: return "E"; case ExoPlayer.STATE_IDLE: return "I"; case ExoPlayer.STATE_PREPARING: return "P"; case ExoPlayer.STATE_READY: return "R"; default: return "?"; } }
Example #13
Source File: EventLogger.java From iview-android-tv with MIT License | 6 votes |
private String getStateString(int state) { switch (state) { case ExoPlayer.STATE_BUFFERING: return "B"; case ExoPlayer.STATE_ENDED: return "E"; case ExoPlayer.STATE_IDLE: return "I"; case ExoPlayer.STATE_PREPARING: return "P"; case ExoPlayer.STATE_READY: return "R"; default: return "?"; } }
Example #14
Source File: PlayerActivity.java From android-tv-leanback with Apache License 2.0 | 6 votes |
private void preparePlayer() { SampleSource sampleSource = new FrameworkSampleSource(this, Uri.parse(mVideo.getContentUrl()), /* headers */ null, RENDERER_COUNT); // Build the track renderers videoRenderer = new MediaCodecVideoTrackRenderer(sampleSource, MediaCodec.VIDEO_SCALING_MODE_SCALE_TO_FIT); TrackRenderer audioRenderer = new MediaCodecAudioTrackRenderer(sampleSource); // Setup the player player = ExoPlayer.Factory.newInstance(RENDERER_COUNT, 1000, 5000); player.addListener(this); // Build the player controls mediaController.setMediaPlayer(new PlayerControl(player)); mediaController.setEnabled(true); player.prepare(videoRenderer, audioRenderer); }
Example #15
Source File: VideoPlayerActivity.java From iview-android-tv with MIT License | 6 votes |
private void updatePlaybackState(int playbackState) { PlaybackState.Builder state = new PlaybackState.Builder(); long position = player.getCurrentPosition(); if (ExoPlayer.STATE_PREPARING == playbackState) { state.setState(PlaybackState.STATE_CONNECTING, position, 1.0f); } else if (ExoPlayer.STATE_BUFFERING == playbackState) { state.setState(PlaybackState.STATE_BUFFERING, position, 1.0f); } else { if (player.getPlayerControl().isPlaying()) { state.setState(PlaybackState.STATE_PLAYING, position, 1.0f); } else { state.setState(PlaybackState.STATE_PAUSED, position, 1.0f); } } mediaSession.setPlaybackState(state.build()); }
Example #16
Source File: IjkExoMediaPlayer.java From talk-android with MIT License | 6 votes |
@Override public boolean isPlaying() { if (mInternalPlayer == null) return false; int state = mInternalPlayer.getPlaybackState(); switch (state) { case ExoPlayer.STATE_BUFFERING: case ExoPlayer.STATE_READY: return mInternalPlayer.getPlayWhenReady(); case ExoPlayer.STATE_IDLE: case ExoPlayer.STATE_PREPARING: case ExoPlayer.STATE_ENDED: default: return false; } }
Example #17
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 #18
Source File: ExVidPlayerImp.java From ExVidPlayer with Apache License 2.0 | 6 votes |
@Override public void run() { switch (player.getPlaybackState()) { case ExoPlayer.STATE_BUFFERING: mlistener.onBuffering(playerControl.getBufferPercentage() + ""); break; case ExoPlayer.STATE_ENDED: mlistener.onCompletion(); break; case ExoPlayer.STATE_IDLE: break; case ExoPlayer.STATE_PREPARING: mlistener.onBufferingStarted(); break; case ExoPlayer.STATE_READY: mlistener.onBufferingFinished(); break; default: break; } mlistener.onProgressChanged((int) player.getCurrentPosition()); mainHandler.postDelayed(updatePlayer, 200); }
Example #19
Source File: VideoPlayerActivity.java From iview-android-tv with MIT License | 6 votes |
private void releasePlayer() { if (player != null) { Log.d(TAG, "Release player"); videoPlayerView.stopDebugView(); playerPosition = player.getCurrentPosition(); long duration = player.getDuration(); player.getPlayerControl().pause(); updatePlaybackState(ExoPlayer.STATE_IDLE); updateMediaSessionIntent(); player.release(); player = null; eventLogger.endSession(); eventLogger = null; timeLogger.endSession(); timeLogger = null; if (playerPosition >= duration) { mediaSession.setActive(false); mediaSession.release(); mediaSession = null; } } }
Example #20
Source File: IjkExoMediaPlayer.java From ShareBox with Apache License 2.0 | 6 votes |
@Override public boolean isPlaying() { if (mInternalPlayer == null) return false; int state = mInternalPlayer.getPlaybackState(); switch (state) { case ExoPlayer.STATE_BUFFERING: case ExoPlayer.STATE_READY: return mInternalPlayer.getPlayWhenReady(); case ExoPlayer.STATE_IDLE: case ExoPlayer.STATE_PREPARING: case ExoPlayer.STATE_ENDED: default: return false; } }
Example #21
Source File: EventLogger.java From ShareBox with Apache License 2.0 | 6 votes |
private String getStateString(int state) { switch (state) { case ExoPlayer.STATE_BUFFERING: return "B"; case ExoPlayer.STATE_ENDED: return "E"; case ExoPlayer.STATE_IDLE: return "I"; case ExoPlayer.STATE_PREPARING: return "P"; case ExoPlayer.STATE_READY: return "R"; default: return "?"; } }
Example #22
Source File: IjkExoMediaPlayer.java From AndroidTvDemo with Apache License 2.0 | 6 votes |
@Override public boolean isPlaying() { if (mInternalPlayer == null) return false; int state = mInternalPlayer.getPlaybackState(); switch (state) { case ExoPlayer.STATE_BUFFERING: case ExoPlayer.STATE_READY: return mInternalPlayer.getPlayWhenReady(); case ExoPlayer.STATE_IDLE: case ExoPlayer.STATE_PREPARING: case ExoPlayer.STATE_ENDED: default: return false; } }
Example #23
Source File: VideoPlayerActivity.java From iview-android-tv with MIT License | 5 votes |
private void updateMediaSessionData() { if (mCurrentEpisode == null) { return; } final MediaMetadata.Builder builder = new MediaMetadata.Builder(); updatePlaybackState(ExoPlayer.STATE_IDLE); updateMediaSessionIntent(); builder.putString(MediaMetadata.METADATA_KEY_DISPLAY_TITLE, mCurrentEpisode.getSeriesTitle()); builder.putString(MediaMetadata.METADATA_KEY_DISPLAY_SUBTITLE, mCurrentEpisode.getTitle()); builder.putLong(MediaMetadata.METADATA_KEY_DURATION, mCurrentEpisode.getDuration() * 1000); builder.putString(MediaMetadata.METADATA_KEY_TITLE, mCurrentEpisode.getSeriesTitle()); builder.putString(MediaMetadata.METADATA_KEY_ARTIST, mCurrentEpisode.getTitle()); Point size = new Point(getResources().getDimensionPixelSize(R.dimen.card_width), getResources().getDimensionPixelSize(R.dimen.card_height)); Picasso.with(this).load(mCurrentEpisode.getThumbnail()).resize(size.x, size.y).into(new Target() { @Override public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from) { builder.putBitmap(MediaMetadata.METADATA_KEY_ART, bitmap); mediaSession.setMetadata(builder.build()); } @Override public void onBitmapFailed(Drawable errorDrawable) { } @Override public void onPrepareLoad(Drawable placeHolderDrawable) { } }); }
Example #24
Source File: VideoPlayer.java From iview-android-tv with MIT License | 5 votes |
public VideoPlayer(RendererBuilder rendererBuilder) { this.rendererBuilder = rendererBuilder; player = ExoPlayer.Factory.newInstance(RENDERER_COUNT, 1000, 5000); player.addListener(this); playerControl = new PlayerControl(player); mainHandler = new Handler(); listeners = new CopyOnWriteArrayList<>(); lastReportedPlaybackState = STATE_IDLE; rendererBuildingState = RENDERER_BUILDING_STATE_IDLE; selectedTracks = new int[RENDERER_COUNT]; // Disable text initially. selectedTracks[TYPE_TEXT] = DISABLED_TRACK; }
Example #25
Source File: VideoPlayerView.java From iview-android-tv with MIT License | 5 votes |
public void onStateChanged(boolean playWhenReady, int playbackState) { if (playbackState == ExoPlayer.STATE_ENDED) { showControls(); } String text = "playWhenReady=" + playWhenReady + ", playbackState="; switch (playbackState) { case ExoPlayer.STATE_BUFFERING: text += "buffering"; showStatusText(R.string.buffering); break; case ExoPlayer.STATE_ENDED: text += "ended"; break; case ExoPlayer.STATE_IDLE: text += "idle"; break; case ExoPlayer.STATE_PREPARING: text += "preparing"; showStatusText(R.string.loading); break; case ExoPlayer.STATE_READY: text += "ready"; hideStatusText(); showShutter(false); if (mPlayer != null && mPlayer.isPlaying()) { hideControlsDelayed(); } break; default: text += "unknown"; break; } playerStateTextView.setText(text); }
Example #26
Source File: VideoControllerView.java From meiShi with Apache License 2.0 | 5 votes |
@TargetApi(21) @Override public void onCompletion(ExoPlayer player) { viewPlay.setImageDrawable(context.getResources().getDrawable(R.mipmap.ic_replay_white_48dp, null)); viewPlay.setVisibility(VISIBLE); viewPlay.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { mVideoView.seekTo(0); setVideoPlayButton(); } }); }
Example #27
Source File: DemoPlayer.java From AndroidTvDemo with Apache License 2.0 | 5 votes |
public DemoPlayer(RendererBuilder rendererBuilder) { this.rendererBuilder = rendererBuilder; player = ExoPlayer.Factory.newInstance(RENDERER_COUNT, 1000, 5000); player.addListener(this); playerControl = new PlayerControl(player); mainHandler = new Handler(); listeners = new CopyOnWriteArrayList<>(); lastReportedPlaybackState = STATE_IDLE; rendererBuildingState = RENDERER_BUILDING_STATE_IDLE; // Disable text initially. player.setSelectedTrack(TYPE_TEXT, TRACK_DISABLED); }
Example #28
Source File: VideoControllerView.java From meiShi with Apache License 2.0 | 5 votes |
@Override public void onBufferingUpdate(ExoPlayer exoPlayer, int percent) { //视频暂停中不显示缓冲进度 if (isVideoPause()) return; if (percent >= 90) { mProgressWheel.setVisibility(View.INVISIBLE); } else { mProgressWheel.setVisibility(View.VISIBLE); mProgressWheel.setText(percent + "%"); } }
Example #29
Source File: DemoPlayer.java From androidtv-sample-inputs with Apache License 2.0 | 5 votes |
@Override public void onPlayerStateChanged(boolean playWhenReady, int state) { for (Callback tvCallback : mTvPlayerCallbacks) { if (playWhenReady && state == ExoPlayer.STATE_ENDED) { tvCallback.onCompleted(); } else if (playWhenReady && state == ExoPlayer.STATE_READY) { tvCallback.onStarted(); } } maybeReportPlayerState(); }
Example #30
Source File: ImaPlayer.java From google-media-framework-android with Apache License 2.0 | 5 votes |
/** * We notify all callbacks when the ad ends. * @param playWhenReady Whether the video should play as soon as it is loaded. * @param playbackState The state of the Exoplayer instance. */ @Override public void onStateChanged(boolean playWhenReady, int playbackState) { if (playbackState == ExoPlayer.STATE_ENDED) { for (VideoAdPlayer.VideoAdPlayerCallback callback : callbacks) { callback.onEnded(); } } }