Search in sources :

Example 11 with ExtractorsFactory

use of androidx.media3.extractor.ExtractorsFactory in project United4 by nilesr.

the class United method playSong.

/**
 * Plays the given song, by finding its R.raw id in the songs map, stored in properties
 * If notify is set set to true, will notify the webpage. For more information, see NotifierService's documentation
 *
 * @param song   the full name of the song to play
 * @param reload whether to notify the web page
 */
public static void playSong(String song, final boolean reload) {
    Log.i(TAG, "playSong called on " + song);
    // Find the filename in the map
    String songs = P.get("songs");
    JsonReader reader = new JsonReader(new StringReader(songs));
    String id = null;
    try {
        reader.beginObject();
        while (reader.hasNext()) {
            String name = reader.nextName();
            String read = reader.nextString();
            // noinspection EqualsReplaceableByObjectsCall
            if (name.equals(song)) {
                id = read;
                Log.i(TAG, "Song id is " + id);
                break;
            }
        }
        reader.close();
    } catch (Exception e) {
        e.printStackTrace();
        return;
    }
    // If we couldn't find it, fucking die
    if (id == null) {
        Log.e(TAG, "Song not found");
        throw new IllegalArgumentException("song not found");
    }
    Log.i(TAG, "Loading sound");
    // Stop any song in progress
    stop();
    // Set some properties in case the javascript forgot to set them
    P.set("is_playing", "true");
    P.set("current_song", song);
    if (player != null) {
        player.stop();
    }
    LoadControl loadControl = new DefaultLoadControl();
    player = ExoPlayerFactory.newSimpleInstance(getContext(), trackSelector, loadControl);
    player.addListener(new SongDoneListener());
    DataSource.Factory dataSourceFactory = new DefaultDataSourceFactory(getContext(), Util.getUserAgent(getContext(), "la/u/ncher"), bandwidthMeter);
    ExtractorsFactory extractorsFactory = new DefaultExtractorsFactory();
    MediaSource mediaSource = new ExtractorMediaSource(Uri.parse("https://niles.xyz/valhalla_music/" + id + ".mp3"), dataSourceFactory, extractorsFactory, null, null);
    player.setPlayWhenReady(true);
    player.prepare(mediaSource);
    if (reload) {
        NotifierService.notify(NotifierService.NotificationType.RELOAD_MUSIC);
    }
}
Also used : DefaultExtractorsFactory(com.google.android.exoplayer2.extractor.DefaultExtractorsFactory) DefaultLoadControl(com.google.android.exoplayer2.DefaultLoadControl) LoadControl(com.google.android.exoplayer2.LoadControl) ExtractorMediaSource(com.google.android.exoplayer2.source.ExtractorMediaSource) ExoPlaybackException(com.google.android.exoplayer2.ExoPlaybackException) DefaultLoadControl(com.google.android.exoplayer2.DefaultLoadControl) DataSource(com.google.android.exoplayer2.upstream.DataSource) 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) StringReader(java.io.StringReader) JsonReader(android.util.JsonReader)

Example 12 with ExtractorsFactory

use of androidx.media3.extractor.ExtractorsFactory in project Camera-Roll-Android-App by kollerlukas.

the class VideoPlayerActivity method initPlayer.

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);
                }
            }
        }
    });
}
Also used : DefaultExtractorsFactory(com.google.android.exoplayer2.extractor.DefaultExtractorsFactory) Drawable(android.graphics.drawable.Drawable) ExtractorMediaSource(com.google.android.exoplayer2.source.ExtractorMediaSource) DataSource(com.google.android.exoplayer2.upstream.DataSource) DefaultLoadControl(com.google.android.exoplayer2.DefaultLoadControl) ImageButton(android.widget.ImageButton) 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) AdaptiveTrackSelection(com.google.android.exoplayer2.trackselection.AdaptiveTrackSelection) SimpleExoPlayerView(com.google.android.exoplayer2.ui.SimpleExoPlayerView) Animatable(android.graphics.drawable.Animatable) DefaultTrackSelector(com.google.android.exoplayer2.trackselection.DefaultTrackSelector) DefaultRenderersFactory(com.google.android.exoplayer2.DefaultRenderersFactory)

Example 13 with ExtractorsFactory

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

the class DefaultMediaSourceFactory method createMediaSource.

@Override
public MediaSource createMediaSource(MediaItem mediaItem) {
    Assertions.checkNotNull(mediaItem.localConfiguration);
    @Nullable String scheme = mediaItem.localConfiguration.uri.getScheme();
    if (scheme != null && scheme.equals(C.SSAI_SCHEME)) {
        return checkNotNull(serverSideAdInsertionMediaSourceFactory).createMediaSource(mediaItem);
    }
    @C.ContentType int type = Util.inferContentTypeForUriAndMimeType(mediaItem.localConfiguration.uri, mediaItem.localConfiguration.mimeType);
    @Nullable MediaSource.Factory mediaSourceFactory = delegateFactoryLoader.getMediaSourceFactory(type);
    checkStateNotNull(mediaSourceFactory, "No suitable media source factory found for content type: " + type);
    MediaItem.LiveConfiguration.Builder liveConfigurationBuilder = mediaItem.liveConfiguration.buildUpon();
    if (mediaItem.liveConfiguration.targetOffsetMs == C.TIME_UNSET) {
        liveConfigurationBuilder.setTargetOffsetMs(liveTargetOffsetMs);
    }
    if (mediaItem.liveConfiguration.minPlaybackSpeed == C.RATE_UNSET) {
        liveConfigurationBuilder.setMinPlaybackSpeed(liveMinSpeed);
    }
    if (mediaItem.liveConfiguration.maxPlaybackSpeed == C.RATE_UNSET) {
        liveConfigurationBuilder.setMaxPlaybackSpeed(liveMaxSpeed);
    }
    if (mediaItem.liveConfiguration.minOffsetMs == C.TIME_UNSET) {
        liveConfigurationBuilder.setMinOffsetMs(liveMinOffsetMs);
    }
    if (mediaItem.liveConfiguration.maxOffsetMs == C.TIME_UNSET) {
        liveConfigurationBuilder.setMaxOffsetMs(liveMaxOffsetMs);
    }
    MediaItem.LiveConfiguration liveConfiguration = liveConfigurationBuilder.build();
    // Make sure to retain the very same media item instance, if no value needs to be overridden.
    if (!liveConfiguration.equals(mediaItem.liveConfiguration)) {
        mediaItem = mediaItem.buildUpon().setLiveConfiguration(liveConfiguration).build();
    }
    MediaSource mediaSource = mediaSourceFactory.createMediaSource(mediaItem);
    List<MediaItem.SubtitleConfiguration> subtitleConfigurations = castNonNull(mediaItem.localConfiguration).subtitleConfigurations;
    if (!subtitleConfigurations.isEmpty()) {
        MediaSource[] mediaSources = new MediaSource[subtitleConfigurations.size() + 1];
        mediaSources[0] = mediaSource;
        for (int i = 0; i < subtitleConfigurations.size(); i++) {
            if (useProgressiveMediaSourceForSubtitles) {
                Format format = new Format.Builder().setSampleMimeType(subtitleConfigurations.get(i).mimeType).setLanguage(subtitleConfigurations.get(i).language).setSelectionFlags(subtitleConfigurations.get(i).selectionFlags).setRoleFlags(subtitleConfigurations.get(i).roleFlags).setLabel(subtitleConfigurations.get(i).label).setId(subtitleConfigurations.get(i).id).build();
                ExtractorsFactory extractorsFactory = () -> new Extractor[] { SubtitleDecoderFactory.DEFAULT.supportsFormat(format) ? new SubtitleExtractor(SubtitleDecoderFactory.DEFAULT.createDecoder(format), format) : new UnknownSubtitlesExtractor(format) };
                mediaSources[i + 1] = new ProgressiveMediaSource.Factory(dataSourceFactory, extractorsFactory).setLoadErrorHandlingPolicy(loadErrorHandlingPolicy).createMediaSource(MediaItem.fromUri(subtitleConfigurations.get(i).uri.toString()));
            } else {
                mediaSources[i + 1] = new SingleSampleMediaSource.Factory(dataSourceFactory).setLoadErrorHandlingPolicy(loadErrorHandlingPolicy).createMediaSource(subtitleConfigurations.get(i), /* durationUs= */
                C.TIME_UNSET);
            }
        }
        mediaSource = new MergingMediaSource(mediaSources);
    }
    return maybeWrapWithAdsMediaSource(mediaItem, maybeClipMediaSource(mediaItem, mediaSource));
}
Also used : SubtitleExtractor(com.google.android.exoplayer2.text.SubtitleExtractor) Format(com.google.android.exoplayer2.Format) AdsMediaSource(com.google.android.exoplayer2.source.ads.AdsMediaSource) ExtractorsFactory(com.google.android.exoplayer2.extractor.ExtractorsFactory) DefaultExtractorsFactory(com.google.android.exoplayer2.extractor.DefaultExtractorsFactory) MediaItem(com.google.android.exoplayer2.MediaItem) Extractor(com.google.android.exoplayer2.extractor.Extractor) SubtitleExtractor(com.google.android.exoplayer2.text.SubtitleExtractor) Nullable(androidx.annotation.Nullable)

Example 14 with ExtractorsFactory

use of androidx.media3.extractor.ExtractorsFactory in project media by androidx.

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(androidx.media3.extractor.DefaultExtractorsFactory) MediaSource(androidx.media3.exoplayer.source.MediaSource) DefaultExtractorsFactory(androidx.media3.extractor.DefaultExtractorsFactory) ExtractorsFactory(androidx.media3.extractor.ExtractorsFactory) DefaultMediaSourceFactory(androidx.media3.exoplayer.source.DefaultMediaSourceFactory) VisibleForTesting(androidx.annotation.VisibleForTesting)

Aggregations

ExtractorsFactory (com.google.android.exoplayer2.extractor.ExtractorsFactory)12 DefaultExtractorsFactory (com.google.android.exoplayer2.extractor.DefaultExtractorsFactory)10 MediaSource (com.google.android.exoplayer2.source.MediaSource)10 DefaultDataSourceFactory (com.google.android.exoplayer2.upstream.DefaultDataSourceFactory)10 ExtractorMediaSource (com.google.android.exoplayer2.source.ExtractorMediaSource)8 DataSource (com.google.android.exoplayer2.upstream.DataSource)7 DefaultLoadControl (com.google.android.exoplayer2.DefaultLoadControl)6 DefaultTrackSelector (com.google.android.exoplayer2.trackselection.DefaultTrackSelector)6 ExoPlayerFactory (com.google.android.exoplayer2.ExoPlayerFactory)3 LoadControl (com.google.android.exoplayer2.LoadControl)3 AudioAttributes (com.google.android.exoplayer2.audio.AudioAttributes)3 AdaptiveTrackSelection (com.google.android.exoplayer2.trackselection.AdaptiveTrackSelection)3 AttachmentDataSourceFactory (org.thoughtcrime.securesms.video.exo.AttachmentDataSourceFactory)3 Nullable (androidx.annotation.Nullable)2 VisibleForTesting (androidx.annotation.VisibleForTesting)2 DefaultExtractorsFactory (androidx.media3.extractor.DefaultExtractorsFactory)2 ExtractorsFactory (androidx.media3.extractor.ExtractorsFactory)2 DefaultRenderersFactory (com.google.android.exoplayer2.DefaultRenderersFactory)2 ConcatenatingMediaSource (com.google.android.exoplayer2.source.ConcatenatingMediaSource)2 TrackSelection (com.google.android.exoplayer2.trackselection.TrackSelection)2