Search in sources :

Example 1 with DefaultRenderersFactory

use of com.google.android.exoplayer2.DefaultRenderersFactory in project PainlessMusicPlayer by Doctoror.

the class ExoMediaPlayer method init.

@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, "Fuck Off Music Player"));
}
Also used : DefaultDataSourceFactory(com.google.android.exoplayer2.upstream.DefaultDataSourceFactory) TrackSelector(com.google.android.exoplayer2.trackselection.TrackSelector) DefaultTrackSelector(com.google.android.exoplayer2.trackselection.DefaultTrackSelector) DefaultTrackSelector(com.google.android.exoplayer2.trackselection.DefaultTrackSelector) DefaultRenderersFactory(com.google.android.exoplayer2.DefaultRenderersFactory) DefaultLoadControl(com.google.android.exoplayer2.DefaultLoadControl)

Example 2 with DefaultRenderersFactory

use of com.google.android.exoplayer2.DefaultRenderersFactory in project AndroidAudioExample by SergeyVinyar.

the class PlayerService method onCreate.

@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);
    // 100 Mb max
    Cache cache = new SimpleCache(new File(this.getCacheDir().getAbsolutePath() + "/exoplayer"), new LeastRecentlyUsedCacheEvictor(1024 * 1024 * 100));
    this.dataSourceFactory = new CacheDataSourceFactory(cache, httpDataSourceFactory, CacheDataSource.FLAG_BLOCK_ON_CACHE | CacheDataSource.FLAG_IGNORE_CACHE_ON_ERROR);
    this.extractorsFactory = new DefaultExtractorsFactory();
}
Also used : Context(android.content.Context) DefaultExtractorsFactory(com.google.android.exoplayer2.extractor.DefaultExtractorsFactory) OkHttpClient(okhttp3.OkHttpClient) NotificationManager(android.app.NotificationManager) LeastRecentlyUsedCacheEvictor(com.google.android.exoplayer2.upstream.cache.LeastRecentlyUsedCacheEvictor) AudioAttributes(android.media.AudioAttributes) PendingIntent(android.app.PendingIntent) Intent(android.content.Intent) MediaSessionCompat(android.support.v4.media.session.MediaSessionCompat) DefaultLoadControl(com.google.android.exoplayer2.DefaultLoadControl) DataSource(com.google.android.exoplayer2.upstream.DataSource) CacheDataSource(com.google.android.exoplayer2.upstream.cache.CacheDataSource) NotificationChannel(android.app.NotificationChannel) SimpleCache(com.google.android.exoplayer2.upstream.cache.SimpleCache) CacheDataSourceFactory(com.google.android.exoplayer2.upstream.cache.CacheDataSourceFactory) DefaultTrackSelector(com.google.android.exoplayer2.trackselection.DefaultTrackSelector) OkHttpDataSourceFactory(com.google.android.exoplayer2.ext.okhttp.OkHttpDataSourceFactory) DefaultRenderersFactory(com.google.android.exoplayer2.DefaultRenderersFactory) File(java.io.File) Cache(com.google.android.exoplayer2.upstream.cache.Cache) SimpleCache(com.google.android.exoplayer2.upstream.cache.SimpleCache)

Example 3 with DefaultRenderersFactory

use of com.google.android.exoplayer2.DefaultRenderersFactory in project NewPipe by TeamNewPipe.

the class BasePlayer method initPlayer.

public void initPlayer() {
    if (DEBUG)
        Log.d(TAG, "initPlayer() called with: context = [" + context + "]");
    if (databaseUpdateReactor != null)
        databaseUpdateReactor.dispose();
    databaseUpdateReactor = new CompositeDisposable();
    final String userAgent = Downloader.USER_AGENT;
    final DefaultBandwidthMeter bandwidthMeter = new DefaultBandwidthMeter();
    dataSource = new PlayerDataSource(context, userAgent, bandwidthMeter);
    final AdaptiveTrackSelection.Factory trackSelectionFactory = new AdaptiveTrackSelection.Factory(bandwidthMeter);
    trackSelector = new CustomTrackSelector(trackSelectionFactory);
    final LoadControl loadControl = new LoadController(context);
    final RenderersFactory renderFactory = new DefaultRenderersFactory(context);
    simpleExoPlayer = ExoPlayerFactory.newSimpleInstance(renderFactory, trackSelector, loadControl);
    simpleExoPlayer.addListener(this);
    simpleExoPlayer.setPlayWhenReady(true);
    simpleExoPlayer.setSeekParameters(PlayerHelper.getSeekParameters(context));
    audioReactor = new AudioReactor(context, simpleExoPlayer);
    mediaSessionManager = new MediaSessionManager(context, simpleExoPlayer, new BasePlayerMediaSession(this));
}
Also used : DefaultBandwidthMeter(com.google.android.exoplayer2.upstream.DefaultBandwidthMeter) LoadControl(com.google.android.exoplayer2.LoadControl) RenderersFactory(com.google.android.exoplayer2.RenderersFactory) ExoPlayerFactory(com.google.android.exoplayer2.ExoPlayerFactory) DefaultRenderersFactory(com.google.android.exoplayer2.DefaultRenderersFactory) MediaSessionManager(org.schabi.newpipe.player.helper.MediaSessionManager) PlayerHelper.getTimeString(org.schabi.newpipe.player.helper.PlayerHelper.getTimeString) RenderersFactory(com.google.android.exoplayer2.RenderersFactory) DefaultRenderersFactory(com.google.android.exoplayer2.DefaultRenderersFactory) AudioReactor(org.schabi.newpipe.player.helper.AudioReactor) BasePlayerMediaSession(org.schabi.newpipe.player.playback.BasePlayerMediaSession) PlayerDataSource(org.schabi.newpipe.player.helper.PlayerDataSource) AdaptiveTrackSelection(com.google.android.exoplayer2.trackselection.AdaptiveTrackSelection) CustomTrackSelector(org.schabi.newpipe.player.playback.CustomTrackSelector) DefaultRenderersFactory(com.google.android.exoplayer2.DefaultRenderersFactory) CompositeDisposable(io.reactivex.disposables.CompositeDisposable) LoadController(org.schabi.newpipe.player.helper.LoadController)

Example 4 with DefaultRenderersFactory

use of com.google.android.exoplayer2.DefaultRenderersFactory in project ExoPlayer by google.

the class DefaultRenderersFactoryAsserts method assertExtensionRendererCreated.

/**
 * Asserts that an extension renderer of type {@code clazz} is not instantiated for {@link
 * DefaultRenderersFactory#EXTENSION_RENDERER_MODE_OFF}, and that it's instantiated in the correct
 * position relative to other renderers of the same type for {@link
 * DefaultRenderersFactory#EXTENSION_RENDERER_MODE_ON} and {@link
 * DefaultRenderersFactory#EXTENSION_RENDERER_MODE_PREFER}, assuming no other extension renderers
 * can be loaded.
 *
 * @param clazz The extension renderer class.
 * @param type The type of the renderer.
 */
public static void assertExtensionRendererCreated(Class<? extends Renderer> clazz, @C.TrackType int type) {
    // In EXTENSION_RENDERER_MODE_OFF the renderer should not be created.
    Renderer[] renderers = createRenderers(EXTENSION_RENDERER_MODE_OFF);
    for (Renderer renderer : renderers) {
        assertThat(renderer).isNotInstanceOf(clazz);
    }
    // In EXTENSION_RENDERER_MODE_ON the renderer should be created and last of its type.
    renderers = createRenderers(EXTENSION_RENDERER_MODE_ON);
    boolean found = false;
    for (Renderer renderer : renderers) {
        if (!found) {
            if (clazz.isInstance(renderer)) {
                found = true;
            }
        } else {
            assertThat(renderer.getTrackType()).isNotEqualTo(type);
        }
    }
    assertThat(found).isTrue();
    // In EXTENSION_RENDERER_MODE_PREFER the renderer should be created and first of its type.
    renderers = createRenderers(EXTENSION_RENDERER_MODE_PREFER);
    found = false;
    for (Renderer renderer : renderers) {
        if (!found) {
            if (clazz.isInstance(renderer)) {
                found = true;
            } else {
                assertThat(renderer.getTrackType()).isNotEqualTo(type);
            }
        } else {
            assertThat(renderer).isNotInstanceOf(clazz);
        }
    }
    assertThat(found).isTrue();
}
Also used : Renderer(com.google.android.exoplayer2.Renderer)

Example 5 with DefaultRenderersFactory

use of com.google.android.exoplayer2.DefaultRenderersFactory in project LeafPic by HoraApps.

the class PlayerActivity method initializePlayer.

// 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(renderersFactory, trackSelector);
        player.addListener(new PlayerEventListener());
        simpleExoPlayerView.setPlayer(player);
        player.setPlayWhenReady(shouldAutoPlay);
    }
    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();
}
Also used : DefaultDataSourceFactory(com.google.android.exoplayer2.upstream.DefaultDataSourceFactory) DefaultExtractorsFactory(com.google.android.exoplayer2.extractor.DefaultExtractorsFactory) DefaultHttpDataSourceFactory(com.google.android.exoplayer2.upstream.DefaultHttpDataSourceFactory) ExoPlayerFactory(com.google.android.exoplayer2.ExoPlayerFactory) DefaultRenderersFactory(com.google.android.exoplayer2.DefaultRenderersFactory) Intent(android.content.Intent) TrackSelectionHelper(org.horaapps.leafpic.views.videoplayer.TrackSelectionHelper) Uri(android.net.Uri) FrameworkMediaCrypto(com.google.android.exoplayer2.drm.FrameworkMediaCrypto) ConcatenatingMediaSource(com.google.android.exoplayer2.source.ConcatenatingMediaSource) DashMediaSource(com.google.android.exoplayer2.source.dash.DashMediaSource) MediaSource(com.google.android.exoplayer2.source.MediaSource) SsMediaSource(com.google.android.exoplayer2.source.smoothstreaming.SsMediaSource) HlsMediaSource(com.google.android.exoplayer2.source.hls.HlsMediaSource) ExtractorMediaSource(com.google.android.exoplayer2.source.ExtractorMediaSource) DefaultTrackSelector(com.google.android.exoplayer2.trackselection.DefaultTrackSelector) ConcatenatingMediaSource(com.google.android.exoplayer2.source.ConcatenatingMediaSource) UnsupportedDrmException(com.google.android.exoplayer2.drm.UnsupportedDrmException) UUID(java.util.UUID) DefaultRenderersFactory(com.google.android.exoplayer2.DefaultRenderersFactory) TrackSelection(com.google.android.exoplayer2.trackselection.TrackSelection) AdaptiveTrackSelection(com.google.android.exoplayer2.trackselection.AdaptiveTrackSelection)

Aggregations

DefaultRenderersFactory (com.google.android.exoplayer2.DefaultRenderersFactory)10 DefaultTrackSelector (com.google.android.exoplayer2.trackselection.DefaultTrackSelector)8 DefaultLoadControl (com.google.android.exoplayer2.DefaultLoadControl)7 AdaptiveTrackSelection (com.google.android.exoplayer2.trackselection.AdaptiveTrackSelection)5 ExtractorMediaSource (com.google.android.exoplayer2.source.ExtractorMediaSource)4 ExoPlayerFactory (com.google.android.exoplayer2.ExoPlayerFactory)3 DefaultExtractorsFactory (com.google.android.exoplayer2.extractor.DefaultExtractorsFactory)3 MediaSource (com.google.android.exoplayer2.source.MediaSource)3 HlsMediaSource (com.google.android.exoplayer2.source.hls.HlsMediaSource)3 DefaultBandwidthMeter (com.google.android.exoplayer2.upstream.DefaultBandwidthMeter)3 DefaultDataSourceFactory (com.google.android.exoplayer2.upstream.DefaultDataSourceFactory)3 Intent (android.content.Intent)2 Uri (android.net.Uri)2 LoadControl (com.google.android.exoplayer2.LoadControl)2 SimpleExoPlayer (com.google.android.exoplayer2.SimpleExoPlayer)2 OkHttpDataSourceFactory (com.google.android.exoplayer2.ext.okhttp.OkHttpDataSourceFactory)2 DashMediaSource (com.google.android.exoplayer2.source.dash.DashMediaSource)2 SsMediaSource (com.google.android.exoplayer2.source.smoothstreaming.SsMediaSource)2 TrackSelection (com.google.android.exoplayer2.trackselection.TrackSelection)2 TrackSelector (com.google.android.exoplayer2.trackselection.TrackSelector)2