Search in sources :

Example 6 with MediaFormat

use of com.google.android.exoplayer.MediaFormat in project edx-app-android by edx.

the class FragmentedMp4Extractor method parseTrak.

/**
 * Parses a trak atom (defined in 14496-12).
 */
private static Track parseTrak(ContainerAtom trak) {
    ContainerAtom mdia = trak.getContainerAtomOfType(Atom.TYPE_mdia);
    int trackType = parseHdlr(mdia.getLeafAtomOfType(Atom.TYPE_hdlr).data);
    Assertions.checkState(trackType == Track.TYPE_AUDIO || trackType == Track.TYPE_VIDEO);
    Pair<Integer, Long> header = parseTkhd(trak.getLeafAtomOfType(Atom.TYPE_tkhd).data);
    int id = header.first;
    // TODO: This value should be used to set a duration field on the Track object
    // instantiated below, however we've found examples where the value is 0. Revisit whether we
    // should set it anyway (and just have it be wrong for bad media streams).
    // long duration = header.second;
    long timescale = parseMdhd(mdia.getLeafAtomOfType(Atom.TYPE_mdhd).data);
    ContainerAtom stbl = mdia.getContainerAtomOfType(Atom.TYPE_minf).getContainerAtomOfType(Atom.TYPE_stbl);
    Pair<MediaFormat, TrackEncryptionBox[]> sampleDescriptions = parseStsd(stbl.getLeafAtomOfType(Atom.TYPE_stsd).data);
    return new Track(id, trackType, timescale, sampleDescriptions.first, sampleDescriptions.second);
}
Also used : MediaFormat(com.google.android.exoplayer.MediaFormat) ContainerAtom(com.google.android.exoplayer.parser.mp4.Atom.ContainerAtom) SuppressLint(android.annotation.SuppressLint)

Example 7 with MediaFormat

use of com.google.android.exoplayer.MediaFormat in project edx-app-android by edx.

the class SmoothStreamingChunkSource method getMediaFormat.

private static MediaFormat getMediaFormat(StreamElement streamElement, int trackIndex) {
    TrackElement trackElement = streamElement.tracks[trackIndex];
    String mimeType = trackElement.mimeType;
    if (streamElement.type == StreamElement.TYPE_VIDEO) {
        MediaFormat format = MediaFormat.createVideoFormat(mimeType, -1, trackElement.maxWidth, trackElement.maxHeight, Arrays.asList(trackElement.csd));
        format.setMaxVideoDimensions(streamElement.maxWidth, streamElement.maxHeight);
        return format;
    } else if (streamElement.type == StreamElement.TYPE_AUDIO) {
        List<byte[]> csd;
        if (trackElement.csd != null) {
            csd = Arrays.asList(trackElement.csd);
        } else {
            csd = Collections.singletonList(CodecSpecificDataUtil.buildAudioSpecificConfig(trackElement.sampleRate, trackElement.numChannels));
        }
        MediaFormat format = MediaFormat.createAudioFormat(mimeType, -1, trackElement.numChannels, trackElement.sampleRate, csd);
        return format;
    }
    // TODO: Do subtitles need a format? MediaFormat supports KEY_LANGUAGE.
    return null;
}
Also used : MediaFormat(com.google.android.exoplayer.MediaFormat) TrackElement(com.google.android.exoplayer.smoothstreaming.SmoothStreamingManifest.TrackElement) List(java.util.List)

Aggregations

MediaFormat (com.google.android.exoplayer.MediaFormat)7 SuppressLint (android.annotation.SuppressLint)4 Point (android.graphics.Point)1 Pair (android.util.Pair)1 ContainerAtom (com.google.android.exoplayer.parser.mp4.Atom.ContainerAtom)1 TrackElement (com.google.android.exoplayer.smoothstreaming.SmoothStreamingManifest.TrackElement)1 SubtitlesDialogFragment (com.zype.android.ui.dialog.SubtitlesDialogFragment)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1