com.google.android.exoplayer2.DefaultRenderersFactory Java Examples
The following examples show how to use
com.google.android.exoplayer2.DefaultRenderersFactory.
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: VideoActivity.java From arcusandroid with Apache License 2.0 | 7 votes |
private void initializePlayer() { CameraPreviewGetter.instance().pauseUpdates(); PlayerView video = findViewById(R.id.video_view); video.setUseController(playbackModel.getType() == PlaybackModel.PlaybackType.CLIP); video.requestFocus(); TrackSelection.Factory trackSelectionFactory = new AdaptiveTrackSelection.Factory(DEFAULT_BANDWIDTH_METER); player = ExoPlayerFactory.newSimpleInstance( new DefaultRenderersFactory(this), new DefaultTrackSelector(trackSelectionFactory), new DefaultLoadControl() ); video.setPlayer(player); String userAgent = Util.getUserAgent(this, getPackageName()); DataSource.Factory dsf = new DefaultDataSourceFactory(this, userAgent); MediaSource mediaSource = new HlsMediaSource.Factory(dsf).createMediaSource(Uri.parse(playbackModel.getUrl())); player.prepare(mediaSource); player.addListener(eventListener); player.setPlayWhenReady(playWhenReady); player.seekTo(currentWindow, playbackPosition); }
Example #2
Source File: ExoPlayer2Helper.java From mimi-reader with Apache License 2.0 | 6 votes |
public ExoPlayer2Helper(Context context) { DefaultBandwidthMeter bandwidthMeter = new DefaultBandwidthMeter(); dataSourceFactory = new FileDataSourceFactory(this); extractorsFactory = new DefaultExtractorsFactory(); DefaultTrackSelector trackSelector = new DefaultTrackSelector(bandwidthMeter); DefaultRenderersFactory renderersFactory = new DefaultRenderersFactory(context); EventLogger eventLogger = new EventLogger(trackSelector); player = ExoPlayerFactory.newSimpleInstance(context, renderersFactory, trackSelector); player.addListener(this); player.addListener(eventLogger); player.setAudioDebugListener(eventLogger); player.setVideoDebugListener(eventLogger); player.setMetadataOutput(eventLogger); player.setVideoListener(this); }
Example #3
Source File: AudioSlidePlayer.java From deltachat-android with GNU General Public License v3.0 | 6 votes |
public void requestDuration() { try { LoadControl loadControl = new DefaultLoadControl.Builder().setBufferDurationsMs(Integer.MAX_VALUE, Integer.MAX_VALUE, Integer.MAX_VALUE, Integer.MAX_VALUE).createDefaultLoadControl(); durationCalculator = ExoPlayerFactory.newSimpleInstance(context, new DefaultRenderersFactory(context), new DefaultTrackSelector(), loadControl); durationCalculator.setPlayWhenReady(false); durationCalculator.addListener(new Player.EventListener() { @Override public void onPlayerStateChanged(boolean playWhenReady, int playbackState) { if (playbackState == Player.STATE_READY) { Util.runOnMain(() -> { Log.d(TAG, "request duration " + durationCalculator.getDuration()); getListener().onReceivedDuration(Long.valueOf(durationCalculator.getDuration()).intValue()); durationCalculator.release(); durationCalculator.removeListener(this); durationCalculator = null; }); } } }); durationCalculator.prepare(createMediaSource(slide.getUri())); } catch (Exception e) { Log.w(TAG, e); getListener().onReceivedDuration(0); } }
Example #4
Source File: ExoMediaPlayer.java From DKVideoPlayer with Apache License 2.0 | 6 votes |
@Override public void initPlayer() { mInternalPlayer = new SimpleExoPlayer.Builder( mAppContext, mRenderersFactory == null ? mRenderersFactory = new DefaultRenderersFactory(mAppContext) : mRenderersFactory, mTrackSelector == null ? mTrackSelector = new DefaultTrackSelector(mAppContext) : mTrackSelector, mLoadControl == null ? mLoadControl = new DefaultLoadControl() : mLoadControl, DefaultBandwidthMeter.getSingletonInstance(mAppContext), Util.getLooper(), new AnalyticsCollector(Clock.DEFAULT), /* useLazyPreparation= */ true, Clock.DEFAULT) .build(); setOptions(); //播放器日志 if (VideoViewManager.getConfig().mIsEnableLog && mTrackSelector instanceof MappingTrackSelector) { mInternalPlayer.addAnalyticsListener(new EventLogger((MappingTrackSelector) mTrackSelector, "ExoPlayer")); } mInternalPlayer.addListener(this); mInternalPlayer.addVideoListener(this); }
Example #5
Source File: TokPlayer.java From Tok-Android with GNU General Public License v3.0 | 5 votes |
public TokPlayer(boolean isAudio) { if (isAudio) { //audio DefaultRenderersFactory renderersFactory = new DefaultRenderersFactory(mContext, DefaultRenderersFactory.EXTENSION_RENDERER_MODE_OFF); DefaultTrackSelector trackSelector = new DefaultTrackSelector(); mPlayer = ExoPlayerFactory.newSimpleInstance(mContext, renderersFactory, trackSelector); mPlayer.addListener(this); mPlayer.addVideoListener(this); } else { //video TODO } }
Example #6
Source File: ExoVideoView.java From ExoVideoView with Apache License 2.0 | 5 votes |
private void createExoPlayer(MediaSourceCreator creator) { if (player != null) { releasePlayer(); } DefaultRenderersFactory renderersFactory = new DefaultRenderersFactory(getContext()); renderersFactory.setExtensionRendererMode(DefaultRenderersFactory.EXTENSION_RENDERER_MODE_OFF); SimpleExoPlayer.Builder builder = new SimpleExoPlayer.Builder(getContext(), renderersFactory); TrackSelection.Factory adaptiveTrackSelectionFactory = new AdaptiveTrackSelection.Factory(); DefaultTrackSelector trackSelector = new DefaultTrackSelector(getContext(),new AdaptiveTrackSelection.Factory()); builder.setTrackSelector(new DefaultTrackSelector(getContext(),adaptiveTrackSelectionFactory)); builder.setTrackSelector(trackSelector); builder.setBandwidthMeter(new DefaultBandwidthMeter.Builder(getContext()).build()); SimpleExoPlayer internalPlayer = builder.build(); internalPlayer.addListener(componentListener); internalPlayer.addListener(creator.getEventLogger()); internalPlayer.addMetadataOutput(creator.getEventLogger()); setPlayer(internalPlayer); }
Example #7
Source File: VodPlaybackFragment.java From xipl with Apache License 2.0 | 5 votes |
/** * Sets up the usage of the internal player used by the library. */ protected void configureInternalPlayer() { Bundle arguments = getArguments(); String url = arguments.getString(VodTvSectionFragment.AV_CONTENT_LINK_BUNDLE); // Configure the ExoPlayer instance that will be used to play the media DataSource.Factory dataSourceFactory = new DefaultDataSourceFactory(getActivity(), Util.getUserAgent(getActivity(), getActivity().getApplicationInfo().loadLabel(getActivity().getPackageManager()).toString())); mSimpleExoPlayer = ExoPlayerFactory.newSimpleInstance(new DefaultRenderersFactory(getActivity()), new DefaultTrackSelector(), new DefaultLoadControl()); ExtractorMediaSource.Factory factory = new ExtractorMediaSource.Factory(dataSourceFactory); Uri uri = Uri.parse(url); mSimpleExoPlayer.prepare(factory.createMediaSource(uri)); mSimpleExoPlayer.addListener(new Player.DefaultEventListener() { @Override public void onPlayerStateChanged(boolean playWhenReady, int playbackState) { super.onPlayerStateChanged(playWhenReady, playbackState); if (playbackState == Player.STATE_READY && mPlayerGlue.getSeekProvider() == null) { mPlayerGlue.setSeekProvider(new ProviderPlaybackSeekDataProvider(mPlayerGlue.getDuration())); // Force content to fit to screen if wanted. if (getVodProperties().isVideoFitToScreen()) { DisplayMetrics displayMetrics = getActivity().getResources().getDisplayMetrics(); mPlayerGlue.getPlayerAdapter().getCallback().onVideoSizeChanged(mPlayerGlue.getPlayerAdapter(), displayMetrics.widthPixels, displayMetrics.heightPixels); } } } }); // Configure Leanback for playback. Use the updatePeriodMs used before in ExoPlayerAdapter LeanbackPlayerAdapter playerAdapter = new LeanbackPlayerAdapter(getActivity(), mSimpleExoPlayer, 16); mPlayerGlue = new PlaybackTransportControlGlue<>(getActivity(), playerAdapter); mPlayerGlue.setHost(new VideoSupportFragmentGlueHost(this)); mPlayerGlue.setTitle(arguments.getString(VodTvSectionFragment.AV_CONTENT_TITLE_BUNDLE)); mPlayerGlue.setSubtitle(arguments.getString(VodTvSectionFragment.AV_CONTENT_GROUP_BUNDLE)); setBackgroundType(BG_LIGHT); mPlayerGlue.playWhenPrepared(); }
Example #8
Source File: ExoMediaPlayer.java From PlayerBase with Apache License 2.0 | 5 votes |
public ExoMediaPlayer(){ mAppContext = AppContextAttach.getApplicationContext(); RenderersFactory renderersFactory = new DefaultRenderersFactory(mAppContext); DefaultTrackSelector trackSelector = new DefaultTrackSelector(mAppContext); mInternalPlayer = new SimpleExoPlayer.Builder(mAppContext, renderersFactory) .setTrackSelector(trackSelector).build(); // Measures bandwidth during playback. Can be null if not required. mBandwidthMeter = new DefaultBandwidthMeter.Builder(mAppContext).build(); mInternalPlayer.addListener(mEventListener); }
Example #9
Source File: ExoPlayerHelper.java From ExoPlayer-Wrapper with Apache License 2.0 | 5 votes |
@Override public void createPlayer(boolean isToPrepare) { if (mExoPlayerListener != null) { mExoPlayerListener.createExoPlayerCalled(isToPrepare); } if (mPlayer != null) { return; } if (isThumbImageViewEnabled) { addThumbImageView(); } mPlayer = ExoPlayerFactory.newSimpleInstance( mContext, new DefaultRenderersFactory(mContext), new DefaultTrackSelector(), mLoadControl); mExoPlayerView.setPlayer(mPlayer); mExoPlayerView.setControllerShowTimeoutMs(1500); mExoPlayerView.setControllerHideOnTouch(false); mTempCurrentVolume = mPlayer.getVolume(); mPlayer.setRepeatMode(isRepeatModeOn ? Player.REPEAT_MODE_ALL : Player.REPEAT_MODE_OFF); mPlayer.setPlayWhenReady(isAutoPlayOn); mPlayer.addListener(this); createMediaSource(); if (isToPrepare) { preparePlayer(); } }
Example #10
Source File: VideoExoPlayer.java From TigerVideo with Apache License 2.0 | 5 votes |
/**--------------------- 创建SimpleExoPlayer ----------------------------**/ private void initExoPlayer() { mMediaDataSourceFactory = buildDataSourceFactory(true); TrackSelection.Factory videoTrackSelectionFactory = new AdaptiveTrackSelection.Factory(BANDWIDTH_METER); mTrackSelector = new DefaultTrackSelector(videoTrackSelectionFactory); mEventLogger = new EventLogger(mTrackSelector); mMainHandler = new Handler(Looper.getMainLooper()); DefaultRenderersFactory renderersFactory = new DefaultRenderersFactory(mContext, null, DefaultRenderersFactory.EXTENSION_RENDERER_MODE_OFF); mExoPlayer = ExoPlayerFactory.newSimpleInstance(renderersFactory, mTrackSelector); mExoPlayer.addListener(mEventLogger); mExoPlayer.setAudioDebugListener(mEventLogger); mExoPlayer.setVideoDebugListener(mEventLogger); mExoPlayer.setMetadataOutput(mEventLogger); mExoPlayer.setTextOutput(null); mExoPlayer.setVideoListener(null); mExoPlayer.removeListener(this); mExoPlayer.setVideoTextureView(null); mExoPlayer.setVideoListener(this); mExoPlayer.addListener(this); mExoPlayer.setTextOutput(this); }
Example #11
Source File: ExoMediaPlayer.java From VideoDemoJava with MIT License | 5 votes |
public ExoMediaPlayer(){ mAppContext = AppContextAttach.getApplicationContext(); RenderersFactory renderersFactory = new DefaultRenderersFactory(mAppContext); DefaultTrackSelector trackSelector = new DefaultTrackSelector(); mInternalPlayer = ExoPlayerFactory.newSimpleInstance(renderersFactory, trackSelector); // Measures bandwidth during playback. Can be null if not required. mBandwidthMeter = new DefaultBandwidthMeter(); mInternalPlayer.addListener(mEventListener); }
Example #12
Source File: ExoMediaPlayer.java From PainlessMusicPlayer with Apache License 2.0 | 5 votes |
@Override public void init(@NonNull final Context context) { final TrackSelector trackSelector = new DefaultTrackSelector(); exoPlayer = ExoPlayerFactory.newSimpleInstance( new DefaultRenderersFactory(context), trackSelector, new DefaultLoadControl()); exoPlayer.addListener(mEventListener); exoPlayer.addAudioDebugListener(mAudioRendererEventListener); dataSourceFactory = new DefaultDataSourceFactory(context, Util.getUserAgent(context, "Painless Music Player")); }
Example #13
Source File: VideoPlayer.java From bcm-android with GNU General Public License v3.0 | 5 votes |
public VideoPlayer(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); inflate(context, R.layout.video_player_layout, this); BandwidthMeter bandwidthMeter = new DefaultBandwidthMeter(); TrackSelection.Factory videoTrackSelectionFactory = new AdaptiveTrackSelection.Factory(bandwidthMeter); TrackSelector trackSelector = new DefaultTrackSelector(videoTrackSelectionFactory); LoadControl loadControl = new DefaultLoadControl(); RenderersFactory renderersFactory = new DefaultRenderersFactory(getContext()); this.exoView = findViewById(R.id.video_view); this.exoPlayer = ExoPlayerFactory.newSimpleInstance(renderersFactory, trackSelector, loadControl); this.exoPlayer.addListener(new ExoPlayerListener()); if (exoView != null) { exoView.setPlayer(exoPlayer); } this.audioView = findViewById(R.id.audio_btn); this.audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE); // VolumeChangeObserver.INSTANCE.registerReceiver(); // VolumeChangeObserver.INSTANCE.addCallback(observerCallback); audioVolume = audioManager.getStreamVolume(AudioManager.STREAM_MUSIC); exoPlayer.setVolume(audioVolume); if (audioVolume == 0) { audioView.setImageResource(R.drawable.common_video_player_mute_icon); isMuted = true; } }
Example #14
Source File: YouTubePlayerV2Fragment.java From SkyTube with GNU General Public License v3.0 | 5 votes |
private SimpleExoPlayer createExoPlayer() { DefaultBandwidthMeter bandwidthMeter = new DefaultBandwidthMeter(); TrackSelection.Factory videoTrackSelectionFactory = new AdaptiveTrackSelection.Factory(); DefaultTrackSelector trackSelector = new DefaultTrackSelector(videoTrackSelectionFactory); Context context = getContext(); DefaultRenderersFactory defaultRenderersFactory = new DefaultRenderersFactory(context); return ExoPlayerFactory.newSimpleInstance(getContext(), defaultRenderersFactory, trackSelector, new DefaultLoadControl(), null, bandwidthMeter); }
Example #15
Source File: SimpleExoPlayerInitializer.java From ChatMessagesAdapter-android with BSD 3-Clause "New" or "Revised" License | 4 votes |
public static SimpleExoPlayer initializeExoPlayer(Context context) { return ExoPlayerFactory.newSimpleInstance( new DefaultRenderersFactory(context), new DefaultTrackSelector(), new DefaultLoadControl()); }
Example #16
Source File: AudioSlidePlayer.java From deltachat-android with GNU General Public License v3.0 | 4 votes |
private void play(final double progress, boolean earpiece) throws IOException { if (this.mediaPlayer != null) { return; } if (slide.getUri() == null) { throw new IOException("Slide has no URI!"); } LoadControl loadControl = new DefaultLoadControl.Builder().setBufferDurationsMs(Integer.MAX_VALUE, Integer.MAX_VALUE, Integer.MAX_VALUE, Integer.MAX_VALUE).createDefaultLoadControl(); this.mediaPlayer = ExoPlayerFactory.newSimpleInstance(context, new DefaultRenderersFactory(context), new DefaultTrackSelector(), loadControl); this.startTime = System.currentTimeMillis(); mediaPlayer.prepare(createMediaSource(slide.getUri())); mediaPlayer.setPlayWhenReady(true); mediaPlayer.setAudioAttributes(new AudioAttributes.Builder() .setContentType(earpiece ? C.CONTENT_TYPE_SPEECH : C.CONTENT_TYPE_MUSIC) .setUsage(earpiece ? C.USAGE_VOICE_COMMUNICATION : C.USAGE_MEDIA) .build()); mediaPlayer.addListener(new Player.EventListener() { boolean started = false; @Override public void onPlayerStateChanged(boolean playWhenReady, int playbackState) { Log.d(TAG, "onPlayerStateChanged(" + playWhenReady + ", " + playbackState + ")"); switch (playbackState) { case Player.STATE_READY: Log.i(TAG, "onPrepared() " + mediaPlayer.getBufferedPercentage() + "% buffered"); synchronized (AudioSlidePlayer.this) { if (mediaPlayer == null) return; Log.d(TAG, "DURATION: " + mediaPlayer.getDuration()); if (started) { Log.d(TAG, "Already started. Ignoring."); return; } started = true; if (progress > 0) { mediaPlayer.seekTo((long) (mediaPlayer.getDuration() * progress)); } setPlaying(AudioSlidePlayer.this); } notifyOnStart(); progressEventHandler.sendEmptyMessage(0); break; case Player.STATE_ENDED: Log.i(TAG, "onComplete"); synchronized (AudioSlidePlayer.this) { getListener().onReceivedDuration(Long.valueOf(mediaPlayer.getDuration()).intValue()); mediaPlayer = null; } notifyOnStop(); progressEventHandler.removeMessages(0); } } @Override public void onPlayerError(ExoPlaybackException error) { Log.w(TAG, "MediaPlayer Error: " + error); Toast.makeText(context, R.string.error, Toast.LENGTH_SHORT).show(); synchronized (AudioSlidePlayer.this) { mediaPlayer = null; } notifyOnStop(); progressEventHandler.removeMessages(0); } }); }
Example #17
Source File: IjkExo2MediaPlayer.java From GSYVideoPlayer with Apache License 2.0 | 4 votes |
public void setRendererFactory(DefaultRenderersFactory rendererFactory) { this.mRendererFactory = rendererFactory; }
Example #18
Source File: QueuedExoPlayer.java From Jockey with Apache License 2.0 | 4 votes |
public QueuedExoPlayer(Context context) { mContext = context; mState = ExoPlayerState.IDLE; mQueue = Collections.emptyList(); mSourceFactory = new DefaultDataSourceFactory(mContext, USER_AGENT); mExtractorsFactory = new DefaultExtractorsFactory(); RenderersFactory renderersFactory = new DefaultRenderersFactory(mContext); TrackSelector trackSelector = new DefaultTrackSelector(new FixedTrackSelection.Factory()); LoadControl loadControl = new DefaultLoadControl(); SimpleExoPlayer baseInstance = ExoPlayerFactory.newSimpleInstance( renderersFactory, trackSelector, loadControl); mExoPlayer = new EqualizedExoPlayer(context, baseInstance); mExoPlayer.addListener(new Player.EventListener() { @Override public void onLoadingChanged(boolean isLoading) { Timber.i("onLoadingChanged (%b)", isLoading); } @Override public void onPlayerStateChanged(boolean playWhenReady, int playbackState) { Timber.i("onPlayerStateChanged"); QueuedExoPlayer.this.onPlayerStateChanged(playbackState); } @Override public void onRepeatModeChanged(int repeatMode) { Timber.i("onRepeatModeChanged (%d)", repeatMode); } @Override public void onShuffleModeEnabledChanged(boolean shuffleModeEnabled) { Timber.i("onShuffleModeEnabledChanged (%b)", shuffleModeEnabled); } @Override public void onTimelineChanged(Timeline timeline, Object manifest) { Timber.i("onTimelineChanged"); dispatchDurationUpdateIfNeeded(); } @Override public void onTracksChanged(TrackGroupArray trackGroups, TrackSelectionArray trackSelections) { Timber.i("onTracksChanged"); } @Override public void onPlayerError(ExoPlaybackException error) { Timber.i("onPlayerError"); QueuedExoPlayer.this.onPlayerError(error); } @Override public void onPositionDiscontinuity(int reason) { Timber.i("onPositionDiscontinuity"); QueuedExoPlayer.this.onPositionDiscontinuity(reason); } @Override public void onPlaybackParametersChanged(PlaybackParameters playbackParameters) { Timber.i("onPlaybackParametersChanged"); } @Override public void onSeekProcessed() { Timber.i("okSeekProcessed"); } }); }
Example #19
Source File: IjkExo2MediaPlayer.java From GSYVideoPlayer with Apache License 2.0 | 4 votes |
public DefaultRenderersFactory getRendererFactory() { return mRendererFactory; }
Example #20
Source File: VideoPlayerActivity.java From Camera-Roll-Android-App with Apache License 2.0 | 4 votes |
private void initPlayer() { // Produces DataSource instances through which media data is loaded. DataSource.Factory dataSourceFactory = new DefaultDataSourceFactory(this, Util.getUserAgent(this, getString(R.string.app_name)), null); // Produces Extractor instances for parsing the media data. ExtractorsFactory extractorsFactory = new DefaultExtractorsFactory(); // This is the MediaSource representing the media to be played. MediaSource videoSource = new ExtractorMediaSource(videoUri, dataSourceFactory, extractorsFactory, null, null); DefaultRenderersFactory renderersFactory = new DefaultRenderersFactory(this); // Create the player player = ExoPlayerFactory.newSimpleInstance(renderersFactory, new DefaultTrackSelector(new AdaptiveTrackSelection.Factory(null)), new DefaultLoadControl()); // Bind the player to the view. SimpleExoPlayerView simpleExoPlayerView = findViewById(R.id.simpleExoPlayerView); simpleExoPlayerView.setPlayer(player); // Prepare the player with the source. player.prepare(videoSource); player.setRepeatMode(Player.REPEAT_MODE_ONE); player.setPlayWhenReady(true); final ImageButton playPause = findViewById(R.id.play_pause); player.addListener(new SimpleEventListener() { @Override public void onPlayerStateChanged(boolean playWhenReady, int playbackState) { //update PlayPause-Button if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && showAnimations()) { if (player.getPlayWhenReady()) { playPause.setImageResource(R.drawable.play_to_pause_avd); } else { playPause.setImageResource(R.drawable.pause_to_play_avd); } Drawable d = playPause.getDrawable(); if (d instanceof Animatable) { ((Animatable) d).start(); } } else { if (player.getPlayWhenReady()) { playPause.setImageResource(R.drawable.ic_pause_white); } else { playPause.setImageResource(R.drawable.ic_play_arrow_white); } } } }); }
Example #21
Source File: PlayerService.java From AndroidAudioExample with MIT License | 4 votes |
@Override public void onCreate() { super.onCreate(); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { @SuppressLint("WrongConstant") NotificationChannel notificationChannel = new NotificationChannel(NOTIFICATION_DEFAULT_CHANNEL_ID, getString(R.string.notification_channel_name), NotificationManagerCompat.IMPORTANCE_DEFAULT); NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); notificationManager.createNotificationChannel(notificationChannel); AudioAttributes audioAttributes = new AudioAttributes.Builder() .setUsage(AudioAttributes.USAGE_MEDIA) .setContentType(AudioAttributes.CONTENT_TYPE_MUSIC) .build(); audioFocusRequest = new AudioFocusRequest.Builder(AudioManager.AUDIOFOCUS_GAIN) .setOnAudioFocusChangeListener(audioFocusChangeListener) .setAcceptsDelayedFocusGain(false) .setWillPauseWhenDucked(true) .setAudioAttributes(audioAttributes) .build(); } audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE); mediaSession = new MediaSessionCompat(this, "PlayerService"); mediaSession.setFlags(MediaSessionCompat.FLAG_HANDLES_MEDIA_BUTTONS | MediaSessionCompat.FLAG_HANDLES_TRANSPORT_CONTROLS); mediaSession.setCallback(mediaSessionCallback); Context appContext = getApplicationContext(); Intent activityIntent = new Intent(appContext, MainActivity.class); mediaSession.setSessionActivity(PendingIntent.getActivity(appContext, 0, activityIntent, 0)); Intent mediaButtonIntent = new Intent(Intent.ACTION_MEDIA_BUTTON, null, appContext, MediaButtonReceiver.class); mediaSession.setMediaButtonReceiver(PendingIntent.getBroadcast(appContext, 0, mediaButtonIntent, 0)); exoPlayer = ExoPlayerFactory.newSimpleInstance(this, new DefaultRenderersFactory(this), new DefaultTrackSelector(), new DefaultLoadControl()); exoPlayer.addListener(exoPlayerListener); DataSource.Factory httpDataSourceFactory = new OkHttpDataSourceFactory(new OkHttpClient(), Util.getUserAgent(this, getString(R.string.app_name))); Cache cache = new SimpleCache(new File(this.getCacheDir().getAbsolutePath() + "/exoplayer"), new LeastRecentlyUsedCacheEvictor(1024 * 1024 * 100)); // 100 Mb max this.dataSourceFactory = new CacheDataSourceFactory(cache, httpDataSourceFactory, CacheDataSource.FLAG_BLOCK_ON_CACHE | CacheDataSource.FLAG_IGNORE_CACHE_ON_ERROR); this.extractorsFactory = new DefaultExtractorsFactory(); }
Example #22
Source File: SimpleRendersFactory.java From DanDanPlayForAndroid with MIT License | 4 votes |
public SimpleRendersFactory(Context context) { super(context); setExtensionRendererMode(DefaultRenderersFactory.EXTENSION_RENDERER_MODE_ON); }
Example #23
Source File: VideoManager.java From jellyfin-androidtv with GNU General Public License v2.0 | 4 votes |
public VideoManager(PlaybackOverlayActivity activity, View view) { mActivity = activity; mSurfaceView = view.findViewById(R.id.player_surface); mSurfaceHolder = mSurfaceView.getHolder(); mSurfaceHolder.addCallback(mSurfaceCallback); mSurfaceFrame = view.findViewById(R.id.player_surface_frame); mSubtitlesSurface = view.findViewById(R.id.subtitles_surface); if (DeviceUtils.is50()) { mSubtitlesSurface.setZOrderMediaOverlay(true); mSubtitlesSurface.getHolder().setFormat(PixelFormat.TRANSLUCENT); hasSubtitlesSurface = true; } else { mSubtitlesSurface.setVisibility(View.GONE); } mExoPlayer = new SimpleExoPlayer.Builder(TvApp.getApplication(), new DefaultRenderersFactory(TvApp.getApplication()) { @Override protected void buildTextRenderers(Context context, TextOutput output, Looper outputLooper, int extensionRendererMode, ArrayList<Renderer> out) { // Do not add text renderers since we handle subtitles } }).build(); mExoPlayerView = view.findViewById(R.id.exoPlayerView); mExoPlayerView.setPlayer(mExoPlayer); mExoPlayer.addListener(new Player.EventListener() { @Override public void onPlayerError(ExoPlaybackException error) { Timber.e("***** Got error from player"); if (errorListener != null) errorListener.onEvent(); stopProgressLoop(); } @Override public void onPlayerStateChanged(boolean playWhenReady, int playbackState) { // Do not call listener when paused if (playbackState == Player.STATE_READY && playWhenReady) { if (preparedListener != null) preparedListener.onEvent(); startProgressLoop(); } else if (playbackState == Player.STATE_ENDED) { if (completionListener != null) completionListener.onEvent(); stopProgressLoop(); } } }); }
Example #24
Source File: ExoPlayerFragment.java From carstream-android-auto with Apache License 2.0 | 4 votes |
@Override public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); titleView = view.findViewById(R.id.player_title); albumView = view.findViewById(R.id.player_album); playerView = view.findViewById(R.id.exoplayer_view); playerView.setControllerVisibilityListener(new PlaybackControlView.VisibilityListener() { @Override public void onVisibilityChange(int visibility) { titleView.setVisibility(visibility); albumView.setVisibility(visibility); mListener.onNativePlayerControlsVisibilityChange(visibility); } }); player = ExoPlayerFactory.newSimpleInstance( new DefaultRenderersFactory(getContext()), new DefaultTrackSelector(), new DefaultLoadControl()); playerView.setPlayer(player); playerView.requestFocus(); player.setPlayWhenReady(true); playerQueue = new PlayerQueue(filePath); MediaSource mediaSource = buildMediaSource(playerQueue); player.seekToDefaultPosition(playerQueue.currentIndex()); player.prepare(mediaSource, true, false); player.addListener(this); setAspectRatio(mListener.getAspectRatio()); playerFocusHelper = new PlayerFocusHelper(getContext()) { @Override protected void onStop() { super.onStop(); player.setPlayWhenReady(false); } @Override protected void onPause() { super.onPause(); player.setPlayWhenReady(false); } @Override public boolean isPlaying() { return player.getPlayWhenReady(); } @Override protected void onPlay() { super.onPlay(); player.setPlayWhenReady(true); } }; }
Example #25
Source File: PlayerActivity.java From leafpicrevived with GNU General Public License v3.0 | 4 votes |
/** * Internal methods */ private void initializePlayer() { Intent intent = getIntent(); boolean needNewPlayer = player == null; if (needNewPlayer) { TrackSelection.Factory adaptiveTrackSelectionFactory = new AdaptiveTrackSelection.Factory(BANDWIDTH_METER); trackSelector = new DefaultTrackSelector(adaptiveTrackSelectionFactory); trackSelectionHelper = new TrackSelectionHelper(trackSelector, adaptiveTrackSelectionFactory, getThemeHelper()); lastSeenTrackGroupArray = null; UUID drmSchemeUuid = intent.hasExtra(DRM_SCHEME_UUID_EXTRA) ? UUID.fromString(intent.getStringExtra(DRM_SCHEME_UUID_EXTRA)) : null; DrmSessionManager<FrameworkMediaCrypto> drmSessionManager = null; if (drmSchemeUuid != null) { String drmLicenseUrl = intent.getStringExtra(DRM_LICENSE_URL); String[] keyRequestPropertiesArray = intent.getStringArrayExtra(DRM_KEY_REQUEST_PROPERTIES); boolean multiSession = intent.getBooleanExtra(DRM_MULTI_SESSION, false); int errorStringId = R.string.error_drm_unknown; try { drmSessionManager = buildDrmSessionManagerV18(drmSchemeUuid, drmLicenseUrl, keyRequestPropertiesArray, multiSession); } catch (UnsupportedDrmException e) { errorStringId = e.reason == UnsupportedDrmException.REASON_UNSUPPORTED_SCHEME ? R.string.error_drm_unsupported_scheme : R.string.error_drm_unknown; } if (drmSessionManager == null) { showToast(errorStringId); return; } } DefaultRenderersFactory renderersFactory = new DefaultRenderersFactory(this, drmSessionManager, DefaultRenderersFactory.EXTENSION_RENDERER_MODE_PREFER); player = ExoPlayerFactory.newSimpleInstance(this.context, trackSelector); player.addListener(new PlayerEventListener()); simpleExoPlayerView.setPlayer(player); player.setPlayWhenReady(shouldAutoPlay); if (Prefs.getLoopVideo()) { player.setRepeatMode(Player.REPEAT_MODE_ALL); } else { player.setRepeatMode(Player.REPEAT_MODE_OFF); } } String action = intent.getAction(); Uri[] uris; String[] extensions; if (intent.getData() != null && intent.getType() != null) { uris = new Uri[]{intent.getData()}; extensions = new String[]{intent.getType()}; } else { // TODO: 12/7/16 asdasd showToast(getString(R.string.unexpected_intent_action, action)); return; } MediaSource[] mediaSources = new MediaSource[uris.length]; for (int i = 0; i < uris.length; i++) { mediaSources[i] = buildMediaSource(uris[i], extensions[i]); } MediaSource mediaSource = mediaSources.length == 1 ? mediaSources[0] : new ConcatenatingMediaSource(mediaSources); boolean haveResumePosition = resumeWindow != C.INDEX_UNSET; if (haveResumePosition) { player.seekTo(resumeWindow, resumePosition); } player.prepare(mediaSource, !haveResumePosition, false); inErrorState = false; supportInvalidateOptionsMenu(); }
Example #26
Source File: VideoPlayer.java From mollyim-android with GNU General Public License v3.0 | 4 votes |
public void setVideoSource(@NonNull VideoSlide videoSource, boolean autoplay) { Context context = getContext(); DefaultRenderersFactory renderersFactory = new DefaultRenderersFactory(context); TrackSelection.Factory videoTrackSelectionFactory = new AdaptiveTrackSelection.Factory(); TrackSelector trackSelector = new DefaultTrackSelector(videoTrackSelectionFactory); LoadControl loadControl = new DefaultLoadControl(); exoPlayer = ExoPlayerFactory.newSimpleInstance(context, renderersFactory, trackSelector, loadControl); exoPlayer.addListener(new ExoPlayerListener(window, playerStateCallback)); exoPlayer.addListener(new Player.DefaultEventListener() { @Override public void onPlayerStateChanged(boolean playWhenReady, int playbackState) { if (playerCallback != null) { switch (playbackState) { case Player.STATE_READY: if (playWhenReady) playerCallback.onPlaying(); break; case Player.STATE_ENDED: playerCallback.onStopped(); break; } } } }); exoView.setPlayer(exoPlayer); exoControls.setPlayer(exoPlayer); DefaultDataSourceFactory defaultDataSourceFactory = new DefaultDataSourceFactory(context, "GenericUserAgent", null); AttachmentDataSourceFactory attachmentDataSourceFactory = new AttachmentDataSourceFactory(context, defaultDataSourceFactory, null); ExtractorsFactory extractorsFactory = new DefaultExtractorsFactory(); createMediaSource = () -> new ExtractorMediaSource.Factory(attachmentDataSourceFactory) .setExtractorsFactory(extractorsFactory) .createMediaSource(videoSource.getUri()); exoPlayer.prepare(createMediaSource.create()); exoPlayer.setPlayWhenReady(autoplay); }
Example #27
Source File: AudioSlidePlayer.java From mollyim-android with GNU General Public License v3.0 | 4 votes |
private void play(final double progress, boolean earpiece) throws IOException { if (this.mediaPlayer != null) { return; } if (slide.getUri() == null) { throw new IOException("Slide has no URI!"); } LoadControl loadControl = new DefaultLoadControl.Builder().setBufferDurationsMs(Integer.MAX_VALUE, Integer.MAX_VALUE, Integer.MAX_VALUE, Integer.MAX_VALUE).createDefaultLoadControl(); this.mediaPlayer = ExoPlayerFactory.newSimpleInstance(context, new DefaultRenderersFactory(context), new DefaultTrackSelector(), loadControl); this.startTime = System.currentTimeMillis(); mediaPlayer.prepare(createMediaSource(slide.getUri())); mediaPlayer.setPlayWhenReady(true); mediaPlayer.setAudioAttributes(new AudioAttributes.Builder() .setContentType(earpiece ? C.CONTENT_TYPE_SPEECH : C.CONTENT_TYPE_MUSIC) .setUsage(earpiece ? C.USAGE_VOICE_COMMUNICATION : C.USAGE_MEDIA) .build()); mediaPlayer.addListener(new Player.EventListener() { boolean started = false; @Override public void onPlayerStateChanged(boolean playWhenReady, int playbackState) { Log.d(TAG, "onPlayerStateChanged(" + playWhenReady + ", " + playbackState + ")"); switch (playbackState) { case Player.STATE_READY: Log.i(TAG, "onPrepared() " + mediaPlayer.getBufferedPercentage() + "% buffered"); synchronized (AudioSlidePlayer.this) { if (mediaPlayer == null) return; if (started) { Log.d(TAG, "Already started. Ignoring."); return; } started = true; if (progress > 0) { mediaPlayer.seekTo((long) (mediaPlayer.getDuration() * progress)); } sensorManager.registerListener(AudioSlidePlayer.this, proximitySensor, SensorManager.SENSOR_DELAY_NORMAL); setPlaying(AudioSlidePlayer.this); } notifyOnStart(); progressEventHandler.sendEmptyMessage(0); break; case Player.STATE_ENDED: Log.i(TAG, "onComplete"); synchronized (AudioSlidePlayer.this) { mediaPlayer = null; sensorManager.unregisterListener(AudioSlidePlayer.this); if (wakeLock != null && wakeLock.isHeld()) { if (Build.VERSION.SDK_INT >= 21) { wakeLock.release(PowerManager.RELEASE_FLAG_WAIT_FOR_NO_PROXIMITY); } } } notifyOnStop(); progressEventHandler.removeMessages(0); } } @Override public void onPlayerError(ExoPlaybackException error) { Log.w(TAG, "MediaPlayer Error: " + error); Toast.makeText(context, R.string.AudioSlidePlayer_error_playing_audio, Toast.LENGTH_SHORT).show(); synchronized (AudioSlidePlayer.this) { mediaPlayer = null; sensorManager.unregisterListener(AudioSlidePlayer.this); if (wakeLock != null && wakeLock.isHeld()) { if (Build.VERSION.SDK_INT >= 21) { wakeLock.release(PowerManager.RELEASE_FLAG_WAIT_FOR_NO_PROXIMITY); } } } notifyOnStop(); progressEventHandler.removeMessages(0); } }); }