Search in sources :

Example 1 with DefaultExtractorsFactory

use of androidx.media3.extractor.DefaultExtractorsFactory in project Signal-Android by signalapp.

the class VideoPlayer method setExoViewSource.

private void setExoViewSource(@NonNull VideoSlide videoSource, boolean autoplay) 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);
    exoPlayer.addListener(new ExoPlayerListener(window));
    // noinspection ConstantConditions
    exoView.setPlayer(exoPlayer);
    DefaultDataSourceFactory defaultDataSourceFactory = new DefaultDataSourceFactory(getContext(), "GenericUserAgent", null);
    AttachmentDataSourceFactory attachmentDataSourceFactory = new AttachmentDataSourceFactory(getContext(), defaultDataSourceFactory, null);
    ExtractorsFactory extractorsFactory = new DefaultExtractorsFactory();
    MediaSource mediaSource = new ExtractorMediaSource(videoSource.getUri(), attachmentDataSourceFactory, extractorsFactory, null, null);
    exoPlayer.prepare(mediaSource);
    exoPlayer.setPlayWhenReady(autoplay);
}
Also used : DefaultExtractorsFactory(com.google.android.exoplayer2.extractor.DefaultExtractorsFactory) DefaultBandwidthMeter(com.google.android.exoplayer2.upstream.DefaultBandwidthMeter) DefaultLoadControl(com.google.android.exoplayer2.DefaultLoadControl) LoadControl(com.google.android.exoplayer2.LoadControl) TrackSelector(com.google.android.exoplayer2.trackselection.TrackSelector) DefaultTrackSelector(com.google.android.exoplayer2.trackselection.DefaultTrackSelector) AttachmentDataSourceFactory(org.thoughtcrime.securesms.video.exo.AttachmentDataSourceFactory) DefaultDataSourceFactory(com.google.android.exoplayer2.upstream.DefaultDataSourceFactory) ExoPlayerFactory(com.google.android.exoplayer2.ExoPlayerFactory) ExtractorsFactory(com.google.android.exoplayer2.extractor.ExtractorsFactory) DefaultExtractorsFactory(com.google.android.exoplayer2.extractor.DefaultExtractorsFactory) ExtractorMediaSource(com.google.android.exoplayer2.source.ExtractorMediaSource) DefaultLoadControl(com.google.android.exoplayer2.DefaultLoadControl) ExtractorMediaSource(com.google.android.exoplayer2.source.ExtractorMediaSource) MediaSource(com.google.android.exoplayer2.source.MediaSource) ExtractorsFactory(com.google.android.exoplayer2.extractor.ExtractorsFactory) DefaultExtractorsFactory(com.google.android.exoplayer2.extractor.DefaultExtractorsFactory) DefaultDataSourceFactory(com.google.android.exoplayer2.upstream.DefaultDataSourceFactory) BandwidthMeter(com.google.android.exoplayer2.upstream.BandwidthMeter) DefaultBandwidthMeter(com.google.android.exoplayer2.upstream.DefaultBandwidthMeter) DefaultTrackSelector(com.google.android.exoplayer2.trackselection.DefaultTrackSelector) TrackSelection(com.google.android.exoplayer2.trackselection.TrackSelection) AdaptiveTrackSelection(com.google.android.exoplayer2.trackselection.AdaptiveTrackSelection) AttachmentDataSourceFactory(org.thoughtcrime.securesms.video.exo.AttachmentDataSourceFactory)

Example 2 with DefaultExtractorsFactory

use of androidx.media3.extractor.DefaultExtractorsFactory in project ExoPlayer by google.

the class MetadataRetriever method retrieveMetadata.

@VisibleForTesting
static /* package */
ListenableFuture<TrackGroupArray> retrieveMetadata(Context context, MediaItem mediaItem, Clock clock) {
    ExtractorsFactory extractorsFactory = new DefaultExtractorsFactory().setMp4ExtractorFlags(Mp4Extractor.FLAG_READ_MOTION_PHOTO_METADATA | Mp4Extractor.FLAG_READ_SEF_DATA);
    MediaSource.Factory mediaSourceFactory = new DefaultMediaSourceFactory(context, extractorsFactory);
    return retrieveMetadata(mediaSourceFactory, mediaItem, clock);
}
Also used : DefaultExtractorsFactory(com.google.android.exoplayer2.extractor.DefaultExtractorsFactory) MediaSource(com.google.android.exoplayer2.source.MediaSource) ExtractorsFactory(com.google.android.exoplayer2.extractor.ExtractorsFactory) DefaultExtractorsFactory(com.google.android.exoplayer2.extractor.DefaultExtractorsFactory) DefaultMediaSourceFactory(com.google.android.exoplayer2.source.DefaultMediaSourceFactory) VisibleForTesting(androidx.annotation.VisibleForTesting)

Example 3 with DefaultExtractorsFactory

use of androidx.media3.extractor.DefaultExtractorsFactory in project android-app by LISTEN-moe.

the class StreamPlayer method init.

private void init() {
    // In case there's already an instance somehow
    releasePlayer();
    final DataSource.Factory dataSourceFactory = new DefaultDataSourceFactory(context, userAgent);
    final ExtractorsFactory extractorsFactory = new DefaultExtractorsFactory();
    final MediaSource streamSource = new ExtractorMediaSource(Uri.parse(streamUrl), dataSourceFactory, extractorsFactory, null, null);
    player = ExoPlayerFactory.newSimpleInstance(context, new DefaultTrackSelector());
    player.prepare(streamSource);
    player.addListener(eventListener);
    player.setVolume(1f);
    final AudioAttributes audioAttributes = new AudioAttributes.Builder().setContentType(CONTENT_TYPE_MUSIC).setUsage(USAGE_MEDIA).build();
    player.setAudioAttributes(audioAttributes);
}
Also used : DefaultExtractorsFactory(com.google.android.exoplayer2.extractor.DefaultExtractorsFactory) ExtractorMediaSource(com.google.android.exoplayer2.source.ExtractorMediaSource) MediaSource(com.google.android.exoplayer2.source.MediaSource) ExtractorsFactory(com.google.android.exoplayer2.extractor.ExtractorsFactory) DefaultExtractorsFactory(com.google.android.exoplayer2.extractor.DefaultExtractorsFactory) DefaultDataSourceFactory(com.google.android.exoplayer2.upstream.DefaultDataSourceFactory) DefaultTrackSelector(com.google.android.exoplayer2.trackselection.DefaultTrackSelector) ExtractorMediaSource(com.google.android.exoplayer2.source.ExtractorMediaSource) AudioAttributes(com.google.android.exoplayer2.audio.AudioAttributes) DataSource(com.google.android.exoplayer2.upstream.DataSource)

Example 4 with DefaultExtractorsFactory

use of androidx.media3.extractor.DefaultExtractorsFactory 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) {
        @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)));
    // 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) SuppressLint(android.annotation.SuppressLint) 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 5 with DefaultExtractorsFactory

use of androidx.media3.extractor.DefaultExtractorsFactory in project Telegram-FOSS by Telegram-FOSS-Team.

the class VideoPlayer method preparePlayer.

public void preparePlayer(Uri uri, String type) {
    this.videoUri = uri;
    this.videoType = type;
    this.audioUri = null;
    this.audioType = null;
    this.loopingMediaSource = false;
    videoPlayerReady = false;
    mixedAudio = false;
    currentUri = uri;
    String scheme = uri.getScheme();
    isStreaming = scheme != null && !scheme.startsWith("file");
    ensurePlayerCreated();
    MediaSource mediaSource;
    switch(type) {
        case "dash":
            mediaSource = new DashMediaSource(uri, mediaDataSourceFactory, new DefaultDashChunkSource.Factory(mediaDataSourceFactory), mainHandler, null);
            break;
        case "hls":
            mediaSource = new HlsMediaSource.Factory(mediaDataSourceFactory).createMediaSource(uri);
            break;
        case "ss":
            mediaSource = new SsMediaSource(uri, mediaDataSourceFactory, new DefaultSsChunkSource.Factory(mediaDataSourceFactory), mainHandler, null);
            break;
        default:
            mediaSource = new ExtractorMediaSource(uri, mediaDataSourceFactory, new DefaultExtractorsFactory(), mainHandler, null);
            break;
    }
    player.prepare(mediaSource, true, true);
}
Also used : DefaultExtractorsFactory(com.google.android.exoplayer2.extractor.DefaultExtractorsFactory) 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) LoopingMediaSource(com.google.android.exoplayer2.source.LoopingMediaSource) DashMediaSource(com.google.android.exoplayer2.source.dash.DashMediaSource) DefaultExtractorsFactory(com.google.android.exoplayer2.extractor.DefaultExtractorsFactory) ExtendedDefaultDataSourceFactory(org.telegram.messenger.secretmedia.ExtendedDefaultDataSourceFactory) DefaultHttpDataSourceFactory(com.google.android.exoplayer2.upstream.DefaultHttpDataSourceFactory) ExoPlayerFactory(com.google.android.exoplayer2.ExoPlayerFactory) DefaultRenderersFactory(com.google.android.exoplayer2.DefaultRenderersFactory) ExtractorMediaSource(com.google.android.exoplayer2.source.ExtractorMediaSource) SsMediaSource(com.google.android.exoplayer2.source.smoothstreaming.SsMediaSource)

Aggregations

DefaultExtractorsFactory (com.google.android.exoplayer2.extractor.DefaultExtractorsFactory)18 MediaSource (com.google.android.exoplayer2.source.MediaSource)12 ExtractorMediaSource (com.google.android.exoplayer2.source.ExtractorMediaSource)11 DefaultDataSourceFactory (com.google.android.exoplayer2.upstream.DefaultDataSourceFactory)11 ExtractorsFactory (com.google.android.exoplayer2.extractor.ExtractorsFactory)9 DefaultRenderersFactory (com.google.android.exoplayer2.DefaultRenderersFactory)8 DefaultTrackSelector (com.google.android.exoplayer2.trackselection.DefaultTrackSelector)8 DataSource (com.google.android.exoplayer2.upstream.DataSource)8 DefaultLoadControl (com.google.android.exoplayer2.DefaultLoadControl)7 Uri (android.net.Uri)5 ExoPlayerFactory (com.google.android.exoplayer2.ExoPlayerFactory)4 AudioAttributes (com.google.android.exoplayer2.audio.AudioAttributes)4 DashMediaSource (com.google.android.exoplayer2.source.dash.DashMediaSource)4 HlsMediaSource (com.google.android.exoplayer2.source.hls.HlsMediaSource)4 SsMediaSource (com.google.android.exoplayer2.source.smoothstreaming.SsMediaSource)4 HashMap (java.util.HashMap)4 SuppressLint (android.annotation.SuppressLint)3 DefaultHttpDataSourceFactory (com.google.android.exoplayer2.upstream.DefaultHttpDataSourceFactory)3 AttachmentDataSourceFactory (org.thoughtcrime.securesms.video.exo.AttachmentDataSourceFactory)3 AmrExtractor (androidx.media3.extractor.amr.AmrExtractor)2