@Override public IBinder onBind(final Intent intent) { bandwidthMeter = new DefaultBandwidthMeter(); TrackSelection.Factory videoTrackSelectionFactory = new AdaptiveTrackSelection.Factory(bandwidthMeter); dataSourceFactory = new DefaultDataSourceFactory(this, Util.getUserAgent(this, "SyncPlayer"), bandwidthMeter); extractorsFactory = new DefaultExtractorsFactory(); TrackSelector trackSelector = new DefaultTrackSelector(videoTrackSelectionFactory); LoadControl loadControl = new DefaultLoadControl(); SimpleExoPlayer player = ExoPlayerFactory.newSimpleInstance(getApplicationContext(), trackSelector, loadControl); mMediaPlayer = player; setCompletionListener(); nbuilder.setSmallIcon(R.mipmap.ic_launcher); return mBinder; }
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 void initializePlayer(Uri videoUri){ if (mExoPlayer == null){ TrackSelector trackSelector = new DefaultTrackSelector(); LoadControl loadControl = new DefaultLoadControl(); mExoPlayer = ExoPlayerFactory.newSimpleInstance(getContext(), trackSelector, loadControl); mExoPlayer.addListener(this); mExoPlayer.seekTo(currentPosition); mPlayerView.setPlayer(mExoPlayer); String userAgent = Util.getUserAgent(getContext(), "Tasty"); MediaSource mediaSource = new ExtractorMediaSource(videoUri, new DefaultDataSourceFactory( getContext(), userAgent), new DefaultExtractorsFactory(), null, null); mExoPlayer.prepare(mediaSource); if (playWhenReady) mExoPlayer.setPlayWhenReady(true); else mExoPlayer.setPlayWhenReady(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; }
@Override public void startPlayer() { if(exoPlayer==null){ exoPlayer = ExoPlayerFactory.newSimpleInstance( context, new DefaultTrackSelector(), new DefaultLoadControl()); exoPlayer.addListener(this); } exoPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC); DataSource.Factory dataSourceFactory = new DefaultDataSourceFactory( context, Util.getUserAgent(context, "uamp"), null); ExtractorsFactory extractorsFactory = new DefaultExtractorsFactory(); MediaSource mediaSource = new ExtractorMediaSource( Uri.parse(currentUrl), dataSourceFactory, extractorsFactory, null, null); exoPlayer.prepare(mediaSource); configPlayer(); }
private void setExoViewSource(@NonNull MasterSecret masterSecret, @NonNull VideoSlide videoSource) throws IOException { BandwidthMeter bandwidthMeter = new DefaultBandwidthMeter(); TrackSelection.Factory videoTrackSelectionFactory = new AdaptiveTrackSelection.Factory(bandwidthMeter); TrackSelector trackSelector = new DefaultTrackSelector(videoTrackSelectionFactory); LoadControl loadControl = new DefaultLoadControl(); exoPlayer = ExoPlayerFactory.newSimpleInstance(getContext(), trackSelector, loadControl); exoView.setPlayer(exoPlayer); DefaultDataSourceFactory defaultDataSourceFactory = new DefaultDataSourceFactory(getContext(), "GenericUserAgent", null); AttachmentDataSourceFactory attachmentDataSourceFactory = new AttachmentDataSourceFactory(getContext(), masterSecret, defaultDataSourceFactory, null); ExtractorsFactory extractorsFactory = new DefaultExtractorsFactory(); MediaSource mediaSource = new ExtractorMediaSource(videoSource.getUri(), attachmentDataSourceFactory, extractorsFactory, null, null); exoPlayer.prepare(mediaSource); exoPlayer.setPlayWhenReady(true); }
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); }
@NonNull public SimpleExoPlayer create(DrmSessionCreator drmSessionCreator, DefaultDrmSessionManager.EventListener drmSessionEventListener, MediaCodecSelector mediaCodecSelector) { DrmSessionManager<FrameworkMediaCrypto> drmSessionManager = drmSessionCreator.create(drmSessionEventListener); RenderersFactory renderersFactory = new SimpleRenderersFactory( context, drmSessionManager, EXTENSION_RENDERER_MODE_OFF, DEFAULT_ALLOWED_VIDEO_JOINING_TIME_MS, mediaCodecSelector ); DefaultLoadControl loadControl = new DefaultLoadControl(); return ExoPlayerFactory.newSimpleInstance(renderersFactory, trackSelector, loadControl); }
public void loadVideo(){ // CommonTools.showErrorLog("test"+"11111111111"); // CommonTools.showErrorLog("test"+playerPosition); if (player == null){ TrackSelection.Factory videoTrackSelectionFactory = new AdaptiveVideoTrackSelection.Factory(BANDWIDTH_METER); trackSelector = new DefaultTrackSelector(mainHandler, videoTrackSelectionFactory); player = ExoPlayerFactory.newSimpleInstance(getContext(), trackSelector, new DefaultLoadControl(), null, false); player.addListener(this); setPlayer(player); // CommonTools.showErrorLog("test"+"222222222"); if (playerPosition > 0){ // CommonTools.showErrorLog("test"+"3333333333"); player.seekTo(playerPosition); } player.setPlayWhenReady(isAutoPlay); } if (uri == null){ // CommonTools.showToast(getContext(), "请选择一个视频来播放"); return; } MediaSource mediaSource = buildMediaSource(uri, null); player.prepare(mediaSource); }
public ExoMediaPlayer(@NonNull Context context) { this.context = context; bufferRepeater.setRepeaterDelay(BUFFER_REPEAT_DELAY); bufferRepeater.setRepeatListener(new BufferRepeatListener()); mainHandler = new Handler(); ComponentListener componentListener = new ComponentListener(); RendererProvider rendererProvider = new RendererProvider(context, mainHandler, componentListener, componentListener, componentListener, componentListener); rendererProvider.setDrmSessionManager(generateDrmSessionManager()); renderers = rendererProvider.generate(); adaptiveTrackSelectionFactory = new AdaptiveTrackSelection.Factory(bandwidthMeter); trackSelector = new DefaultTrackSelector(adaptiveTrackSelectionFactory); LoadControl loadControl = ExoMedia.Data.loadControl != null ? ExoMedia.Data.loadControl : new DefaultLoadControl(); player = ExoPlayerFactory.newInstance(renderers.toArray(new Renderer[renderers.size()]), trackSelector, loadControl); player.addListener(this); }
private void initializePlayer() { if (player == null) { TrackSelection.Factory videoTrackSelectionFactory = new AdaptiveVideoTrackSelection.Factory(BANDWIDTH_METER); trackSelector = new DefaultTrackSelector(videoTrackSelectionFactory); player = ExoPlayerFactory.newSimpleInstance(getContext(), trackSelector, new DefaultLoadControl()); player.addListener(this); exoPlayerView.setPlayer(player); if (isTimelineStatic) { if (playerPosition == C.TIME_UNSET) { player.seekToDefaultPosition(playerWindow); } else { player.seekTo(playerWindow, playerPosition); } } audioBecomingNoisyReceiver.setListener(this); setPlayWhenReady(!isPaused); playerNeedsSource = true; } if (playerNeedsSource && srcUri != null) { MediaSource mediaSource = buildMediaSource(srcUri, extension); mediaSource = repeat ? new LoopingMediaSource(mediaSource) : mediaSource; player.prepare(mediaSource, !shouldRestorePosition, true); playerNeedsSource = false; eventEmitter.loadStart(); loadVideoStarted = true; } }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); if (!isPlaying) { Handler mainHandler = new Handler(); BandwidthMeter bandwidthMeter = new DefaultBandwidthMeter(); TrackSelection.Factory videoTrackSelectionFactory = new AdaptiveVideoTrackSelection.Factory(bandwidthMeter); TrackSelector trackSelector = new DefaultTrackSelector(videoTrackSelectionFactory); LoadControl loadControl = new DefaultLoadControl(); SimpleExoPlayer player = ExoPlayerFactory.newSimpleInstance(MainActivity.this, trackSelector, loadControl); SimpleExoPlayerView playerView = (SimpleExoPlayerView) findViewById(R.id.videoView); playerView.setPlayer(player); DataSource.Factory dataSourceFactory = new DefaultDataSourceFactory(MainActivity.this, Util.getUserAgent(MainActivity.this, "yourApplicationName")); MediaSource mediaSource = new ExtractorMediaSource(Uri.parse("https://r7---sn-3c27ln7k.googlevideo.com/videoplayback?id=6fb497d0971b8cdf&itag=22&source=picasa&begin=0&requiressl=yes&mm=30&mn=sn-3c27ln7k&ms=nxu&mv=m&nh=IgphcjAzLmticDAxKgkxMjcuMC4wLjE&pl=22&sc=yes&mime=video/mp4&lmt=1486083166327499&mt=1486135406&ip=134.249.158.189&ipbits=8&expire=1486164239&sparams=ip,ipbits,expire,id,itag,source,requiressl,mm,mn,ms,mv,nh,pl,sc,mime,lmt&signature=3BB06D8D4294F8C49B3CE910B3D6849954302BB1.02ABE00700DFCEF715E72D0EFB73B67841E659F8&key=ck2&ratebypass=yes&title=%5BAnime365%5D%20Kuzu%20no%20Honkai%20-%2004%20(t1174045)"), dataSourceFactory, new DefaultExtractorsFactory(), null, null); player.prepare(mediaSource); player.setPlayWhenReady(true); } }
private void initializePlayer(Uri mediaUri) { if (mExoPlayer == null) { // Create an instance of the ExoPlayer. TrackSelector trackSelector = new DefaultTrackSelector(); LoadControl loadControl = new DefaultLoadControl(); mExoPlayer = ExoPlayerFactory.newSimpleInstance(getContext(), trackSelector, loadControl); binding.exoStepFragmentPlayerView.setPlayer(mExoPlayer); mExoPlayer.addListener(this); String userAgent = Util.getUserAgent(getContext(), "RecipeStepVideo"); MediaSource mediaSource = new ExtractorMediaSource(mediaUri, new DefaultDataSourceFactory( getContext(), userAgent), new DefaultExtractorsFactory(), null, null); mExoPlayer.prepare(mediaSource); mExoPlayer.setPlayWhenReady(true); } }
@SuppressWarnings("unused") protected SimpleExoPlayer buildExoPlayer(HostActivity host, Surface surface, MappingTrackSelector trackSelector, DrmSessionManager<FrameworkMediaCrypto> drmSessionManager) { SimpleExoPlayer player = ExoPlayerFactory.newSimpleInstance(host, trackSelector, new DefaultLoadControl(), drmSessionManager, SimpleExoPlayer.EXTENSION_RENDERER_MODE_OFF, 0); player.setVideoSurface(surface); return player; }
@Override protected SimpleExoPlayer buildExoPlayer(HostActivity host, Surface surface, MappingTrackSelector trackSelector, DrmSessionManager<FrameworkMediaCrypto> drmSessionManager) { SimpleExoPlayer player = new DebugSimpleExoPlayer(host, trackSelector, new DefaultLoadControl(), drmSessionManager); player.setVideoSurface(surface); return player; }
@Override public void doPrepar(Context context, String url, Map<String, String> headers) { release(); TrackSelection.Factory videoTrackSelectionFactory = new AdaptiveVideoTrackSelection.Factory(BANDWIDTH_METER); DefaultTrackSelector trackSelector = new DefaultTrackSelector(mainThreadHandler, videoTrackSelectionFactory); simpleExoPlayer = ExoPlayerFactory.newSimpleInstance(context, trackSelector, new DefaultLoadControl(), null, false); simpleExoPlayer.setPlayWhenReady(true); MediaSource mediaSource = buildMediaSource(context, Uri.parse(url)); simpleExoPlayer.addListener(ExoMedia.this); simpleExoPlayer.setVideoListener(ExoMedia.this); simpleExoPlayer.prepare(mediaSource, true, true); }
/** * 播放启动视频 */ private void startPlayer() { // 0. set player view playerView = (SimpleExoPlayerView) findViewById(R.id.playerView); playerView.setUseController(false); playerView.getKeepScreenOn(); playerView.setResizeMode(RESIZE_MODE_FILL); // 1. Create a default TrackSelector TrackSelection.Factory videoTrackSelectionFactory = new AdaptiveTrackSelection.Factory(new DefaultBandwidthMeter()); trackSelector = new DefaultTrackSelector(videoTrackSelectionFactory); // 2. Create a default LoadControl loadControl = new DefaultLoadControl(); // 3. Create the mPlayer mPlayer = ExoPlayerFactory.newSimpleInstance(this, trackSelector, loadControl); mPlayer.addListener(this); // 4. set player playerView.setPlayer(mPlayer); mPlayer.setPlayWhenReady(true); // 5. prepare to play File file = new File(Constants.FILE_VIDEO_FLODER, "jcode.mp4"); if (file.isFile() && file.exists()) { mUri = Uri.fromFile(file); } else { Toast.makeText(this,"文件未找到",Toast.LENGTH_SHORT).show(); return; } ExtractorsFactory extractorsFactory = new DefaultExtractorsFactory(); DataSource.Factory dataSourceFactory = new DefaultDataSourceFactory(this, "UserAgent"); videoSource = new ExtractorMediaSource(mUri, dataSourceFactory, extractorsFactory, null, null); // 6. ready to play mPlayer.prepare(videoSource); }
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(); }
public PlayerController(Context context) { this.bandwidthMeter = new DefaultBandwidthMeter(); this.loadControl = new DefaultLoadControl(); this.extractorsFactory = new DefaultExtractorsFactory(); this.trackSelectionFactory = new AdaptiveTrackSelection.Factory(bandwidthMeter); this.dataSourceFactory = new DefaultDataSourceFactory(context, Util.getUserAgent(context.getApplicationContext(), TAG_NAME), (TransferListener<? super DataSource>) bandwidthMeter); this.trackSelector = new DefaultTrackSelector(trackSelectionFactory); this.player = ExoPlayerFactory.newSimpleInstance(context, this.trackSelector, this.loadControl); this.playerView = new PlayerView(context,this.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(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 void setUpExoPlayer() { // Create a default TrackSelector TrackSelector trackSelector = createTrackSelector(); // Create a default LoadControl LoadControl loadControl = new DefaultLoadControl(); // Create the player exoPlayer = ExoPlayerFactory.newSimpleInstance(getContext(), trackSelector, loadControl); resumeLocalVideo(); exoPlayer.addListener(exoPlayerEventListener); }
private void setUpExoPlayer() { // Create a default TrackSelector TrackSelector trackSelector = createTrackSelector(); // Create a default LoadControl LoadControl loadControl = new DefaultLoadControl(); // Create the player exoPlayer = ExoPlayerFactory.newSimpleInstance(this, trackSelector, loadControl); resumeLocalVideo(); exoPlayer.addListener(exoPlayerEventListener); }
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); }
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_player); media = (MediaFile) getIntent().getSerializableExtra(MEDIA); videoFragment = (VideoFragment) getFragmentManager().findFragmentById(R.id.playback_fragment); VideoFragmentGlueHost glueHost = new VideoFragmentGlueHost(videoFragment); subtitleView = (SubtitleView) findViewById(R.id.subtitle_view); if (subtitleView != null) { subtitleView.setUserDefaultStyle(); subtitleView.setUserDefaultTextSize(); } Handler mainHandler = new Handler(); BandwidthMeter bandwidthMeter = new DefaultBandwidthMeter(); TrackSelection.Factory videoTrackSelectionFactory = new AdaptiveVideoTrackSelection.Factory(bandwidthMeter); MappingTrackSelector trackSelector = new DefaultTrackSelector(mainHandler, videoTrackSelectionFactory); LoadControl loadControl = new DefaultLoadControl(); player = ExoPlayerFactory.newSimpleInstance(this, trackSelector, loadControl); player.addListener(this); player.setTextOutput(this); glueHelper = new ExoPlayerGlue(player, trackSelector, this); glueHelper.setHost(glueHost); session = new MediaSession(this, "ITPlayer"); session.setCallback(new ExoPlayerMediaSessionCalback(player)); session.setFlags(MediaSession.FLAG_HANDLES_MEDIA_BUTTONS | MediaSession.FLAG_HANDLES_TRANSPORT_CONTROLS); session.setActive(true); MediaMetadata.Builder metaBuilder = new MediaMetadata.Builder(); session.setMetadata(metaBuilder.build()); new SourceTask().execute(media); }
/** * Constructor. */ public ExoPlayerAdapter(Context context) { mContext = context; mPlayer = ExoPlayerFactory.newSimpleInstance(mContext, new DefaultTrackSelector(), new DefaultLoadControl()); mPlayer.addListener(this); }
@Override public void init(@NonNull final Context context) { final TrackSelector trackSelector = new DefaultTrackSelector(); mExoPlayer = ExoPlayerFactory .newSimpleInstance(context, trackSelector, new DefaultLoadControl()); mExoPlayer.addListener(mEventListener); mExoPlayer.setAudioDebugListener(mAudioRendererEventListener); mDataSourceFactory = new DefaultDataSourceFactory(context, Util.getUserAgent(context, "Fuck Off Music Player")); mExtractorsFactory = new DefaultExtractorsFactory(); }
private void setUpExoPlayer(){ // Create a default TrackSelector TrackSelector trackSelector = createTrackSelector(); // Create a default LoadControl LoadControl loadControl = new DefaultLoadControl(); // Create the player exoPlayer = ExoPlayerFactory.newSimpleInstance(getContext(), trackSelector, loadControl); resumeLocalVideo(); exoPlayer.addListener(exoPlayerEventListener); }
private static LoadControl getNewLoadControl() { return new DefaultLoadControl( new DefaultAllocator(false, C.DEFAULT_BUFFER_SEGMENT_SIZE), DefaultLoadControl.DEFAULT_MIN_BUFFER_MS, maxBufferMs.getObject(), DefaultLoadControl.DEFAULT_BUFFER_FOR_PLAYBACK_MS, DefaultLoadControl.DEFAULT_BUFFER_FOR_PLAYBACK_AFTER_REBUFFER_MS, DefaultLoadControl.DEFAULT_TARGET_BUFFER_BYTES, DefaultLoadControl.DEFAULT_PRIORITIZE_TIME_OVER_SIZE_THRESHOLDS); }
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 public void onCreate() { Log.d("MediaService", "OnCreate"); // Load controls BandwidthMeter bandwidthMeter = new DefaultBandwidthMeter(); TrackSelection.Factory videoFactory = new AdaptiveTrackSelection.Factory(bandwidthMeter); TrackSelector trackSelector = new DefaultTrackSelector(videoFactory); LoadControl loadControl = new DefaultLoadControl(); // Create Player player = ExoPlayerFactory.newSimpleInstance(getApplicationContext(), trackSelector, loadControl); }
public ExoPlayerView(Context context, AttributeSet attrs) { super(context, attrs); if (isInEditMode()) { return; } handler = new Handler(); player = ExoPlayerFactory.newSimpleInstance(context, new DefaultTrackSelector(), new DefaultLoadControl()); player.setVideoTextureView(this); player.addVideoListener(this); player.addListener(this); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_video); Bundle bundle = getIntent().getExtras(); if(bundle!=null && bundle.containsKey("multimedia")) { Multimedia multimedia = bundle.getParcelable("multimedia"); SimpleExoPlayerView videoView = (SimpleExoPlayerView) findViewById(R.id.video); // 1. Crea un slector de pista por defecto BandwidthMeter bandwidthMeter = new DefaultBandwidthMeter(); TrackSelection.Factory videoTrackSelectionFactory = new AdaptiveVideoTrackSelection.Factory(bandwidthMeter); TrackSelector trackSelector = new DefaultTrackSelector(videoTrackSelectionFactory); // 2. Creo un control para el player LoadControl loadControl = new DefaultLoadControl(); // 3. Creo el player con los componentes anteriores player = ExoPlayerFactory.newSimpleInstance(getApplicationContext(), trackSelector, loadControl); //Obtengo la URL completa del archivo de video Uri uri = Uri.parse(ConsultasBBDD.server + ConsultasBBDD.imagenes + multimedia.getUrl()); //A la vista le establezco el reproductor que va a usar videoView.setPlayer(player); // Procuce que se instancie el DataSource a través de los datos del video que ha sido cargado. DataSource.Factory dataSourceFactory = new DefaultDataSourceFactory(getApplicationContext(), Util.getUserAgent(getApplicationContext(), "SmartU")); // Produce un extractor que parsea el video. ExtractorsFactory extractorsFactory = new DefaultExtractorsFactory(); // Construyo un MediaSource con el formato y los datos del video para asignarselo al reproductor. MediaSource videoSource = new ExtractorMediaSource(uri, dataSourceFactory, extractorsFactory, null, null); // If has subtitles load video with subtitles if (multimedia.getUrlSubtitulos() != null && multimedia.getUrlSubtitulos().compareTo("") != 0) { //Obtengo la URL completa para los subtitulos del video Uri subtitulosUri = Uri.parse(ConsultasBBDD.server + ConsultasBBDD.imagenes + multimedia.getUrlSubtitulos()); //Asigno el formato de los subtitulos Format textFormat = Format.createTextSampleFormat(null, MimeTypes.TEXT_VTT, null, Format.NO_VALUE, Format.NO_VALUE, Locale.getDefault().getLanguage(), null); //Creo un MediaSource para los subtitulos para añadirselos al video MediaSource subtitleSource = new SingleSampleMediaSource(subtitulosUri, dataSourceFactory, textFormat, C.TIME_UNSET); // Mezcla el video con los subtitulos MergingMediaSource mergedSource = new MergingMediaSource(videoSource, subtitleSource); // Preparo el reproductor con los subtitulos y el video player.prepare(mergedSource); } else // Si no tiene subtitulos preparo solo el video player.prepare(videoSource); } }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_video); ButterKnife.bind(this); getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION); getWindow().getDecorView().setSystemUiVisibility( View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_FULLSCREEN | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY); path = getIntent().getExtras().getString("MEDIA_URI"); fab.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { finish(); } }); TrackSelection.Factory videoTrackSelectionFactory = new AdaptiveVideoTrackSelection.Factory(null); TrackSelector trackSelector = new DefaultTrackSelector(videoTrackSelectionFactory); LoadControl loadControl = new DefaultLoadControl(); player = ExoPlayerFactory.newSimpleInstance(this, trackSelector, loadControl); playerView.setPlayer(player); DataSource.Factory dataSourceFactory = new DefaultDataSourceFactory(this, Util.getUserAgent(this, "org.polaric.cluttr"), null); ExtractorsFactory extractorsFactory = new DefaultExtractorsFactory(); MediaSource videoSource = new ExtractorMediaSource(Uri.parse(path), dataSourceFactory, extractorsFactory, null, null); player.prepare(videoSource); playerView.setControllerVisibilityListener(new PlaybackControlView.VisibilityListener() { @Override public void onVisibilityChange(int visibility) { if (visibility==View.VISIBLE) { fab.show(); } else { fab.hide(); } } }); }