/*** * 创建实例播放实例,并不开始缓冲 **/ private SimpleExoPlayer createFullPlayer() { TrackSelection.Factory videoTrackSelectionFactory = new AdaptiveTrackSelection.Factory(new DefaultBandwidthMeter()); TrackSelector trackSelector = new DefaultTrackSelector(videoTrackSelectionFactory); BufferingLoadControl loadControl = new BufferingLoadControl(); if (null == modelType) { setDefaultLoadModel(); } else { loadControl.setListener(new LoadListener() { @Override public void onProgress(long pro) { getPlayerViewListener().showNetSpeed(String.valueOf(pro) + "%"); } }); } DefaultRenderersFactory rf = new DefaultRenderersFactory(activity, drmSessionManager, DefaultRenderersFactory.EXTENSION_RENDERER_MODE_ON); SimpleExoPlayer player = ExoPlayerFactory.newSimpleInstance(rf, trackSelector, loadControl); player.setPlaybackParameters(playbackParameters); getPlayerViewListener().setPlayer(player); return player; }
private void initializePlayer() { if (player == null) { // a factory to create an AdaptiveVideoTrackSelection TrackSelection.Factory adaptiveTrackSelectionFactory = new AdaptiveTrackSelection.Factory(BANDWIDTH_METER); // using a DefaultTrackSelector with an adaptive video selection factory player = ExoPlayerFactory.newSimpleInstance(new DefaultRenderersFactory(this), new DefaultTrackSelector(adaptiveTrackSelectionFactory), new DefaultLoadControl()); player.addListener(componentListener); player.addVideoDebugListener(componentListener); player.addAudioDebugListener(componentListener); playerView.setPlayer(player); player.setPlayWhenReady(playWhenReady); player.seekTo(currentWindow, playbackPosition); } MediaSource mediaSource = buildMediaSource(Uri.parse(getString(R.string.media_url_dash))); player.prepare(mediaSource, true, false); }
private SimpleExoPlayer setupPlayer(){ Log.d(TAG,"Setting up Player."); videoView.setKeepScreenOn(true); mUserAgent = Util.getUserAgent(getContext(), getResources().getString(R.string.app_name)); AdaptiveTrackSelection.Factory trackSelectorFactory = new AdaptiveTrackSelection.Factory(BANDWIDTH_METER); DefaultTrackSelector trackSelector = new DefaultTrackSelector(trackSelectorFactory); LoadControl loadControl = new DefaultLoadControl(); DefaultRenderersFactory renderersFactory = new DefaultRenderersFactory(getContext(), null, DefaultRenderersFactory.EXTENSION_RENDERER_MODE_OFF); exoPlayer = ExoPlayerFactory.newSimpleInstance(renderersFactory, trackSelector, loadControl); MyListener listener = new MyListener(exoPlayer, this); exoPlayer.addVideoListener(listener); exoPlayer.addListener(listener); exoPlayer.setPlayWhenReady(mPlaybackState); exoPlayer.prepare(buildMediaSource(Uri.parse(mRecording.getRecordingUrl()),"")); return exoPlayer; }
private void setupExoPlayer() { TrackSelection.Factory adaptiveTrackSelectionFactory = new AdaptiveTrackSelection.Factory(new DefaultBandwidthMeter()); exoPlayer = ExoPlayerFactory.newSimpleInstance( new DefaultRenderersFactory(this), new DefaultTrackSelector(adaptiveTrackSelectionFactory), new DefaultLoadControl()); pvVideoPreview.setPlayer(exoPlayer); exoPlayer.setPlayWhenReady(true); Uri uri = Uri.parse("asset:///sample_video.mp4"); MediaSource mediaSource = createMediaSource(this, uri); LoopingMediaSource loopingMediaSource = new LoopingMediaSource(mediaSource); exoPlayer.prepare(loopingMediaSource, true, false); }
private void initializePlayer() { if (player == null) { player = ExoPlayerFactory.newSimpleInstance(new DefaultRenderersFactory(this), new DefaultTrackSelector(), new DefaultLoadControl()); playerView.setPlayer(player); player.setPlayWhenReady(playWhenReady); player.seekTo(currentWindow, playbackPosition); } MediaSource mediaSource = buildMediaSource(Uri.parse(getString(R.string.media_url_mp4))); player.prepare(mediaSource, true, false); }
private void initializePlayer() { if (player == null) { // a factory to create an AdaptiveVideoTrackSelection TrackSelection.Factory adaptiveTrackSelectionFactory = new AdaptiveTrackSelection.Factory(BANDWIDTH_METER); // let the factory create a player instance with default components player = ExoPlayerFactory.newSimpleInstance(new DefaultRenderersFactory(this), new DefaultTrackSelector(adaptiveTrackSelectionFactory), new DefaultLoadControl()); playerView.setPlayer(player); player.setPlayWhenReady(playWhenReady); player.seekTo(currentWindow, playbackPosition); } MediaSource mediaSource = buildMediaSource(Uri.parse(getString(R.string.media_url_dash))); player.prepare(mediaSource, true, false); }
@Override public void onCreate() { super.onCreate(); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { 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(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)), null); 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(); }
private SimpleExoPlayer createFullPlayer() { TrackSelection.Factory videoTrackSelectionFactory = new AdaptiveTrackSelection.Factory(new DefaultBandwidthMeter()); TrackSelector trackSelector = new DefaultTrackSelector(videoTrackSelectionFactory); LoadControl loadControl = new DefaultLoadControl(); SimpleExoPlayer player = ExoPlayerFactory.newSimpleInstance( new DefaultRenderersFactory(playerView.getContext()), trackSelector, loadControl); player.setPlayWhenReady(true); player.prepare(mediaSourceBuilder.getMediaSource(false)); player.addListener(eventListener); return player; }
private SimpleExoPlayer createFullPlayer() { TrackSelection.Factory videoTrackSelectionFactory = new AdaptiveTrackSelection.Factory(new DefaultBandwidthMeter()); TrackSelector trackSelector = new DefaultTrackSelector(videoTrackSelectionFactory); LoadControl loadControl = new DefaultLoadControl(); SimpleExoPlayer player = ExoPlayerFactory.newSimpleInstance( new DefaultRenderersFactory(playerView.getContext()), trackSelector, loadControl); player.setPlayWhenReady(true); player.prepare(mediaSourceBuilder.getMediaSource(false)); player.addListener(this); return player; }
private SimpleExoPlayer createPreviewPlayer() { TrackSelection.Factory videoTrackSelectionFactory = new WorstVideoTrackSelection.Factory(); TrackSelector trackSelector = new DefaultTrackSelector(videoTrackSelectionFactory); LoadControl loadControl = new PreviewLoadControl(); SimpleExoPlayer player = ExoPlayerFactory.newSimpleInstance( new DefaultRenderersFactory(playerView.getContext()), trackSelector, loadControl); player.setPlayWhenReady(false); player.setVolume(0f); player.prepare(mediaSourceBuilder.getMediaSource(true)); return player; }
private void createExoPlayer() { if (mExoPlayer != null) { releaseExoPlayer(); } // create default TrackSelector TrackSelector trackSelector = new DefaultTrackSelector(); // create default LoadControl - double the buffer LoadControl loadControl = new DefaultLoadControl(new DefaultAllocator(true, C.DEFAULT_BUFFER_SEGMENT_SIZE * 2)); // create the player mExoPlayer = ExoPlayerFactory.newSimpleInstance(new DefaultRenderersFactory(getApplicationContext()), trackSelector, loadControl); }
@Override public void prepareAsync() throws IllegalStateException { if (mInternalPlayer != null) throw new IllegalStateException("can't prepare a prepared player"); TrackSelection.Factory videoTrackSelectionFactory = new AdaptiveTrackSelection.Factory(new DefaultBandwidthMeter()); mTrackSelector = new DefaultTrackSelector(videoTrackSelectionFactory); mEventLogger = new EventLogger(mTrackSelector); boolean preferExtensionDecoders = true; boolean useExtensionRenderers = true;//是否开启扩展 @DefaultRenderersFactory.ExtensionRendererMode int extensionRendererMode = useExtensionRenderers ? (preferExtensionDecoders ? DefaultRenderersFactory.EXTENSION_RENDERER_MODE_PREFER : DefaultRenderersFactory.EXTENSION_RENDERER_MODE_ON) : DefaultRenderersFactory.EXTENSION_RENDERER_MODE_OFF; renderersFactory = new DefaultRenderersFactory(mAppContext, null, extensionRendererMode); DefaultLoadControl loadControl = new DefaultLoadControl(); mInternalPlayer = new SimpleExoPlayer2(renderersFactory, mTrackSelector, loadControl); mInternalPlayer.addListener(this); mInternalPlayer.setVideoDebugListener(this); mInternalPlayer.setAudioDebugListener(this); mInternalPlayer.addListener(mEventLogger); if (mSpeedPlaybackParameters != null) { mInternalPlayer.setPlaybackParameters(mSpeedPlaybackParameters); } if (mSurface != null) mInternalPlayer.setVideoSurface(mSurface); mInternalPlayer.prepare(mMediaSource); mInternalPlayer.setPlayWhenReady(false); }
/**--------------------- 创建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); }
public ExoPlayerPlayableFilePreparationSourceProvider(Context context, BestMatchUriProvider bestMatchUriProvider, RemoteFileUriProvider remoteFileUriProvider, Library library) { this.bestMatchUriProvider = bestMatchUriProvider; this.remoteFileUriProvider = remoteFileUriProvider; final AudioCacheConfiguration audioCacheConfiguration = new AudioCacheConfiguration(library); final CachedFilesProvider cachedFilesProvider = new CachedFilesProvider(context, audioCacheConfiguration); final DiskFileAccessTimeUpdater diskFileAccessTimeUpdater = new DiskFileAccessTimeUpdater(context); final IDiskCacheDirectoryProvider diskCacheDirectoryProvider = new AndroidDiskCacheDirectoryProvider(context); final DiskFileCacheStreamSupplier diskFileCacheStream = new DiskFileCacheStreamSupplier( diskCacheDirectoryProvider, audioCacheConfiguration, new DiskFileCachePersistence( context, diskCacheDirectoryProvider, audioCacheConfiguration, cachedFilesProvider, diskFileAccessTimeUpdater), cachedFilesProvider); extractorMediaSourceFactoryProvider = new ExtractorMediaSourceFactoryProvider(context, library, diskFileCacheStream); diskFileCache = new DiskFileCache( context, diskCacheDirectoryProvider, audioCacheConfiguration, diskFileCacheStream, cachedFilesProvider, diskFileAccessTimeUpdater); renderersFactory = new DefaultRenderersFactory(context); handler = new Handler(context.getMainLooper()); }
@SuppressWarnings("unused") protected SimpleExoPlayer buildExoPlayer(HostActivity host, Surface surface, MappingTrackSelector trackSelector, DrmSessionManager<FrameworkMediaCrypto> drmSessionManager) { RenderersFactory renderersFactory = new DefaultRenderersFactory(host, drmSessionManager, DefaultRenderersFactory.EXTENSION_RENDERER_MODE_OFF, 0); SimpleExoPlayer player = ExoPlayerFactory.newSimpleInstance(renderersFactory, trackSelector); player.setVideoSurface(surface); return player; }
private void createPlayer() { if (mPlayer != null) { releasePlayer(); } // create default TrackSelector TrackSelector trackSelector = new DefaultTrackSelector(); // create default LoadControl - double the buffer LoadControl loadControl = new DefaultLoadControl(new DefaultAllocator(true, C.DEFAULT_BUFFER_SEGMENT_SIZE * 2)); // create the player mPlayer = ExoPlayerFactory.newSimpleInstance(new DefaultRenderersFactory(getApplicationContext()), trackSelector, loadControl); }
@Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_video_player); //Dagger ((TgbApp) getApplication()).getAppComponent().inject(this); //Butterknife ButterKnife.bind(this); // Get the media router service. mMediaRouter = MediaRouter.getInstance(this); //Elements toolbar = playerView.findViewById(R.id.toolbar); backdrop = playerView.findViewById(R.id.backdrop); playerPoster = playerView.findViewById(R.id.poster); setSupportActionBar(toolbar); getSupportActionBar().setHomeButtonEnabled(true); getSupportActionBar().setDisplayHomeAsUpEnabled(true); setSupportActionBar(toolbar); //ExoPlayer mainHandler = new Handler(); dataSourceFactory = ((TgbApp) getApplication()).buildHttpDataSourceFactory(BANDWIDTH_METER); // Create a route selector for the type of routes your app supports. mSelector = new MediaRouteSelector.Builder() // These are the framework-supported intents .addControlCategory(MediaControlIntent.CATEGORY_REMOTE_PLAYBACK) .build(); //Create new player instance player = ExoPlayerFactory.newSimpleInstance( new DefaultRenderersFactory(this), new DefaultTrackSelector(), new DefaultLoadControl()); //Associate player to view playerView.setPlayer(player); //Player settings player.addListener(this); player.setPlayWhenReady(true); playerView.showController(); playerView.setControllerHideOnTouch(false); initializeUI(); }
static InternalExoPlayer newInstance(Context context, TrackSelector trackSelector) { return newInstance(new DefaultRenderersFactory(context), trackSelector); }
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) { 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_24dp); } else { playPause.setImageResource(R.drawable.ic_play_arrow_white_24dp); } } } }); }
public static SimpleExoPlayer initializeExoPlayer(Context context) { return ExoPlayerFactory.newSimpleInstance( new DefaultRenderersFactory(context), new DefaultTrackSelector(), new DefaultLoadControl()); }
public DebugRenderersFactory(Context context, DrmSessionManager<FrameworkMediaCrypto> drmSessionManager) { super(context, drmSessionManager, DefaultRenderersFactory.EXTENSION_RENDERER_MODE_OFF, 0); }
private void createExoPlayer() { if (mExoPlayer != null) { releaseExoPlayer(); } DefaultRenderersFactory renderersFactory = new DefaultRenderersFactory(this, null, DefaultRenderersFactory.EXTENSION_RENDERER_MODE_OFF); TrackSelector trackSelector = new DefaultTrackSelector(); LoadControl loadControl = new DefaultLoadControl(new DefaultAllocator(true, C.DEFAULT_BUFFER_SEGMENT_SIZE * 2)); mExoPlayer = ExoPlayerFactory.newSimpleInstance(renderersFactory, trackSelector, loadControl); }