Search in sources :

Example 1 with MdtaMetadataEntry

use of androidx.media3.extractor.metadata.mp4.MdtaMetadataEntry in project react-native-track-player by react-native-kit.

the class SourceMetadata method handleQuickTimeMetadata.

/**
 * QuickTime MDTA metadata (mov, qt)
 *
 * https://developer.apple.com/library/archive/documentation/QuickTime/QTFF/Metadata/Metadata.html
 */
private static void handleQuickTimeMetadata(MusicManager manager, Metadata metadata) {
    String title = null, artist = null, album = null, date = null, genre = null;
    for (int i = 0; i < metadata.length(); i++) {
        Metadata.Entry entry = metadata.get(i);
        if (!(entry instanceof MdtaMetadataEntry))
            continue;
        MdtaMetadataEntry mdta = (MdtaMetadataEntry) entry;
        String key = mdta.key;
        try {
            if (key.equals("com.apple.quicktime.title")) {
                title = new String(mdta.value, "UTF-8");
            } else if (key.equals("com.apple.quicktime.artist")) {
                artist = new String(mdta.value, "UTF-8");
            } else if (key.equals("com.apple.quicktime.album")) {
                album = new String(mdta.value, "UTF-8");
            } else if (key.equals("com.apple.quicktime.creationdate")) {
                date = new String(mdta.value, "UTF-8");
            } else if (key.equals("com.apple.quicktime.genre")) {
                genre = new String(mdta.value, "UTF-8");
            }
        } catch (Exception ex) {
        // Ignored
        }
    }
    if (title != null || artist != null || album != null || date != null || genre != null) {
        manager.onMetadataReceived("quicktime", title, null, artist, album, date, genre);
    }
}
Also used : Metadata(com.google.android.exoplayer2.metadata.Metadata) MdtaMetadataEntry(com.google.android.exoplayer2.extractor.mp4.MdtaMetadataEntry)

Example 2 with MdtaMetadataEntry

use of androidx.media3.extractor.metadata.mp4.MdtaMetadataEntry in project media by androidx.

the class MetadataRetrieverTest method retrieveMetadata_sefSlowMotion_outputsExpectedMetadata.

@Test
public void retrieveMetadata_sefSlowMotion_outputsExpectedMetadata() throws Exception {
    MediaItem mediaItem = MediaItem.fromUri(Uri.parse("asset://android_asset/media/mp4/sample_sef_slow_motion.mp4"));
    SmtaMetadataEntry expectedSmtaEntry = new SmtaMetadataEntry(/* captureFrameRate= */
    240, /* svcTemporalLayerCount= */
    4);
    List<SlowMotionData.Segment> segments = new ArrayList<>();
    segments.add(new SlowMotionData.Segment(/* startTimeMs= */
    88, /* endTimeMs= */
    879, /* speedDivisor= */
    2));
    segments.add(new SlowMotionData.Segment(/* startTimeMs= */
    1255, /* endTimeMs= */
    1970, /* speedDivisor= */
    8));
    SlowMotionData expectedSlowMotionData = new SlowMotionData(segments);
    MdtaMetadataEntry expectedMdtaEntry = new MdtaMetadataEntry(KEY_ANDROID_CAPTURE_FPS, /* value= */
    new byte[] { 67, 112, 0, 0 }, /* localeIndicator= */
    0, /* typeIndicator= */
    23);
    ListenableFuture<TrackGroupArray> trackGroupsFuture = retrieveMetadata(context, mediaItem, clock);
    ShadowLooper.idleMainLooper();
    TrackGroupArray trackGroups = trackGroupsFuture.get(TEST_TIMEOUT_SEC, TimeUnit.SECONDS);
    // Video and audio
    assertThat(trackGroups.length).isEqualTo(2);
    // Audio
    assertThat(trackGroups.get(0).getFormat(0).metadata.length()).isEqualTo(2);
    assertThat(trackGroups.get(0).getFormat(0).metadata.get(0)).isEqualTo(expectedSmtaEntry);
    assertThat(trackGroups.get(0).getFormat(0).metadata.get(1)).isEqualTo(expectedSlowMotionData);
    // Video
    assertThat(trackGroups.get(1).getFormat(0).metadata.length()).isEqualTo(3);
    assertThat(trackGroups.get(1).getFormat(0).metadata.get(0)).isEqualTo(expectedMdtaEntry);
    assertThat(trackGroups.get(1).getFormat(0).metadata.get(1)).isEqualTo(expectedSmtaEntry);
    assertThat(trackGroups.get(1).getFormat(0).metadata.get(2)).isEqualTo(expectedSlowMotionData);
}
Also used : SmtaMetadataEntry(androidx.media3.extractor.metadata.mp4.SmtaMetadataEntry) MediaItem(androidx.media3.common.MediaItem) SlowMotionData(androidx.media3.extractor.metadata.mp4.SlowMotionData) ArrayList(java.util.ArrayList) TrackGroupArray(androidx.media3.common.TrackGroupArray) MdtaMetadataEntry(androidx.media3.extractor.metadata.mp4.MdtaMetadataEntry) Test(org.junit.Test)

Example 3 with MdtaMetadataEntry

use of androidx.media3.extractor.metadata.mp4.MdtaMetadataEntry in project ExoPlayer by google.

the class MetadataRetrieverTest method retrieveMetadata_sefSlowMotion_outputsExpectedMetadata.

@Test
public void retrieveMetadata_sefSlowMotion_outputsExpectedMetadata() throws Exception {
    MediaItem mediaItem = MediaItem.fromUri(Uri.parse("asset://android_asset/media/mp4/sample_sef_slow_motion.mp4"));
    SmtaMetadataEntry expectedSmtaEntry = new SmtaMetadataEntry(/* captureFrameRate= */
    240, /* svcTemporalLayerCount= */
    4);
    List<SlowMotionData.Segment> segments = new ArrayList<>();
    segments.add(new SlowMotionData.Segment(/* startTimeMs= */
    88, /* endTimeMs= */
    879, /* speedDivisor= */
    2));
    segments.add(new SlowMotionData.Segment(/* startTimeMs= */
    1255, /* endTimeMs= */
    1970, /* speedDivisor= */
    8));
    SlowMotionData expectedSlowMotionData = new SlowMotionData(segments);
    MdtaMetadataEntry expectedMdtaEntry = new MdtaMetadataEntry(KEY_ANDROID_CAPTURE_FPS, /* value= */
    new byte[] { 67, 112, 0, 0 }, /* localeIndicator= */
    0, /* typeIndicator= */
    23);
    ListenableFuture<TrackGroupArray> trackGroupsFuture = retrieveMetadata(context, mediaItem, clock);
    ShadowLooper.idleMainLooper();
    TrackGroupArray trackGroups = trackGroupsFuture.get(TEST_TIMEOUT_SEC, TimeUnit.SECONDS);
    // Video and audio
    assertThat(trackGroups.length).isEqualTo(2);
    // Audio
    assertThat(trackGroups.get(0).getFormat(0).metadata.length()).isEqualTo(2);
    assertThat(trackGroups.get(0).getFormat(0).metadata.get(0)).isEqualTo(expectedSmtaEntry);
    assertThat(trackGroups.get(0).getFormat(0).metadata.get(1)).isEqualTo(expectedSlowMotionData);
    // Video
    assertThat(trackGroups.get(1).getFormat(0).metadata.length()).isEqualTo(3);
    assertThat(trackGroups.get(1).getFormat(0).metadata.get(0)).isEqualTo(expectedMdtaEntry);
    assertThat(trackGroups.get(1).getFormat(0).metadata.get(1)).isEqualTo(expectedSmtaEntry);
    assertThat(trackGroups.get(1).getFormat(0).metadata.get(2)).isEqualTo(expectedSlowMotionData);
}
Also used : SmtaMetadataEntry(com.google.android.exoplayer2.metadata.mp4.SmtaMetadataEntry) SlowMotionData(com.google.android.exoplayer2.metadata.mp4.SlowMotionData) ArrayList(java.util.ArrayList) TrackGroupArray(com.google.android.exoplayer2.source.TrackGroupArray) MdtaMetadataEntry(com.google.android.exoplayer2.metadata.mp4.MdtaMetadataEntry) Test(org.junit.Test)

Aggregations

ArrayList (java.util.ArrayList)2 Test (org.junit.Test)2 MediaItem (androidx.media3.common.MediaItem)1 TrackGroupArray (androidx.media3.common.TrackGroupArray)1 MdtaMetadataEntry (androidx.media3.extractor.metadata.mp4.MdtaMetadataEntry)1 SlowMotionData (androidx.media3.extractor.metadata.mp4.SlowMotionData)1 SmtaMetadataEntry (androidx.media3.extractor.metadata.mp4.SmtaMetadataEntry)1 MdtaMetadataEntry (com.google.android.exoplayer2.extractor.mp4.MdtaMetadataEntry)1 Metadata (com.google.android.exoplayer2.metadata.Metadata)1 MdtaMetadataEntry (com.google.android.exoplayer2.metadata.mp4.MdtaMetadataEntry)1 SlowMotionData (com.google.android.exoplayer2.metadata.mp4.SlowMotionData)1 SmtaMetadataEntry (com.google.android.exoplayer2.metadata.mp4.SmtaMetadataEntry)1 TrackGroupArray (com.google.android.exoplayer2.source.TrackGroupArray)1