本文整理汇总了Java中com.google.android.exoplayer.MediaFormat类的典型用法代码示例。如果您正苦于以下问题:Java MediaFormat类的具体用法?Java MediaFormat怎么用?Java MediaFormat使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
MediaFormat类属于com.google.android.exoplayer包,在下文中一共展示了MediaFormat类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: buildTrackName
import com.google.android.exoplayer.MediaFormat; //导入依赖的package包/类
private static String buildTrackName(MediaFormat format) {
if (format.adaptive) {
return "auto";
}
String trackName;
if (MimeTypes.isVideo(format.mimeType)) {
trackName = joinWithSeparator(joinWithSeparator(buildResolutionString(format), buildBitrateString(format)),
buildTrackIdString(format));
} else if (MimeTypes.isAudio(format.mimeType)) {
trackName = joinWithSeparator(
joinWithSeparator(joinWithSeparator(buildLanguageString(format), buildAudioPropertyString(format)),
buildBitrateString(format)),
buildTrackIdString(format));
} else {
trackName = joinWithSeparator(joinWithSeparator(buildLanguageString(format), buildBitrateString(format)),
buildTrackIdString(format));
}
return trackName.length() == 0 ? "unknown" : trackName;
}
示例2: doPrepare
import com.google.android.exoplayer.MediaFormat; //导入依赖的package包/类
@Override
protected boolean doPrepare(long positionUs) throws ExoPlaybackException {
boolean sourcePrepared = mSource.prepare(positionUs);
if (!sourcePrepared) {
return false;
}
int trackCount = mSource.getTrackCount();
for (int i = 0; i < trackCount; ++i) {
MediaFormat trackFormat = mSource.getFormat(i);
if (handlesMimeType(trackFormat.mimeType)) {
mTrackIndex = i;
clearDecodeState();
return true;
}
}
// TODO: Check this case. (Source do not have the proper mime type.)
return true;
}
示例3: init
import com.google.android.exoplayer.MediaFormat; //导入依赖的package包/类
@Override
public void init(@NonNull List<String> ids, @NonNull List<MediaFormat> mediaFormats)
throws IOException {
mTrackCount = ids.size();
if (mTrackCount <= 0) {
throw new IOException("No tracks to initialize");
}
mIds = ids;
mTrackSelected = new boolean[mTrackCount];
mReadSampleQueues = new ArrayList<>();
mSampleChunkIoHelper = new SampleChunkIoHelper(ids, mediaFormats, mBufferReason,
mBufferManager, mSamplePool, mIoCallback);
for (int i = 0; i < mTrackCount; ++i) {
mReadSampleQueues.add(i, new SampleQueue(mSamplePool));
}
mSampleChunkIoHelper.init();
}
示例4: SampleChunkIoHelper
import com.google.android.exoplayer.MediaFormat; //导入依赖的package包/类
/**
* Creates {@link SampleChunk} I/O handler.
*
* @param ids track names
* @param mediaFormats {@link android.media.MediaFormat} for each track
* @param bufferReason reason to be buffered
* @param bufferManager manager of {@link SampleChunk} collections
* @param samplePool allocator for a sample
* @param ioCallback listeners for I/O events
*/
public SampleChunkIoHelper(List<String> ids, List<MediaFormat> mediaFormats,
@BufferReason int bufferReason, BufferManager bufferManager, SamplePool samplePool,
IoCallback ioCallback) {
mTrackCount = ids.size();
mIds = ids;
mMediaFormats = mediaFormats;
mBufferReason = bufferReason;
mBufferManager = bufferManager;
mSamplePool = samplePool;
mIoCallback = ioCallback;
mReadSampleBuffers = new ConcurrentLinkedQueue[mTrackCount];
mHandlerReadSampleBuffers = new ConcurrentLinkedQueue[mTrackCount];
mWriteEndPositionUs = new long[mTrackCount];
mReadIoStates = new SampleChunk.IoState[mTrackCount];
mWriteIoStates = new SampleChunk.IoState[mTrackCount];
for (int i = 0; i < mTrackCount; ++i) {
mWriteEndPositionUs[i] = RecordingSampleBuffer.CHUNK_DURATION_US;
mReadIoStates[i] = new SampleChunk.IoState();
mWriteIoStates[i] = new SampleChunk.IoState();
}
}
示例5: read
import com.google.android.exoplayer.MediaFormat; //导入依赖的package包/类
@Override
public int read(ExtractorInput input, PositionHolder seekPosition)
throws IOException, InterruptedException {
if (synchronizedHeaderData == 0 && !synchronizeCatchingEndOfInput(input)) {
return RESULT_END_OF_INPUT;
}
if (seeker == null) {
setupSeeker(input);
extractorOutput.seekMap(seeker);
MediaFormat mediaFormat = MediaFormat.createAudioFormat(null, synchronizedHeader.mimeType,
MediaFormat.NO_VALUE, MpegAudioHeader.MAX_FRAME_SIZE_BYTES, seeker.getDurationUs(),
synchronizedHeader.channels, synchronizedHeader.sampleRate, null, null);
if (gaplessInfo != null) {
mediaFormat =
mediaFormat.copyWithGaplessInfo(gaplessInfo.encoderDelay, gaplessInfo.encoderPadding);
}
trackOutput.format(mediaFormat);
}
return readSample(input);
}
示例6: testParsesValidMp4File
import com.google.android.exoplayer.MediaFormat; //导入依赖的package包/类
public void testParsesValidMp4File() throws Exception {
TestUtil.consumeTestData(extractor,
getTestInputData(true /* includeStss */, false /* mp4vFormat */));
// The seek map is correct.
assertSeekMap(extractorOutput.seekMap, true);
// The video and audio formats are set correctly.
assertEquals(2, extractorOutput.trackOutputs.size());
MediaFormat videoFormat = extractorOutput.trackOutputs.get(0).format;
MediaFormat audioFormat = extractorOutput.trackOutputs.get(1).format;
assertEquals(MimeTypes.VIDEO_H264, videoFormat.mimeType);
assertEquals(VIDEO_WIDTH, videoFormat.width);
assertEquals(VIDEO_HEIGHT, videoFormat.height);
assertEquals(MimeTypes.AUDIO_AAC, audioFormat.mimeType);
// The timestamps and sizes are set correctly.
FakeTrackOutput videoTrackOutput = extractorOutput.trackOutputs.get(0);
videoTrackOutput.assertSampleCount(SAMPLE_TIMESTAMPS.length);
for (int i = 0; i < SAMPLE_TIMESTAMPS.length; i++) {
byte[] sampleData = getOutputSampleData(i, true);
int sampleFlags = SAMPLE_IS_SYNC[i] ? C.SAMPLE_FLAG_SYNC : 0;
long sampleTimestampUs = getVideoTimestampUs(SAMPLE_TIMESTAMPS[i]);
videoTrackOutput.assertSample(i, sampleData, sampleTimestampUs, sampleFlags, null);
}
}
示例7: parseAnnexFEAc3Format
import com.google.android.exoplayer.MediaFormat; //导入依赖的package包/类
/**
* Returns the AC-3 format given {@code data} containing the EC3SpecificBox according to
* ETSI TS 102 366 Annex F.
*/
public static MediaFormat parseAnnexFEAc3Format(ParsableByteArray data) {
data.skipBytes(2); // Skip data_rate and num_ind_sub.
// Read only the first substream.
// TODO: Read later substreams?
// fscod (sample rate code)
int fscod = (data.readUnsignedByte() & 0xC0) >> 6;
int sampleRate = SAMPLE_RATES[fscod];
int nextByte = data.readUnsignedByte();
// Map acmod (audio coding mode) onto a channel count.
int channelCount = CHANNEL_COUNTS[(nextByte & 0x0E) >> 1];
// lfeon (low frequency effects on)
if ((nextByte & 0x01) != 0) {
channelCount++;
}
return MediaFormat.createAudioFormat(MimeTypes.AUDIO_EC3, MediaFormat.NO_VALUE,
channelCount, sampleRate, null);
}
示例8: getTrackFormat
import com.google.android.exoplayer.MediaFormat; //导入依赖的package包/类
private static MediaFormat getTrackFormat(int adaptationSetType, Format format,
String mediaMimeType, long durationUs) {
switch (adaptationSetType) {
case AdaptationSet.TYPE_VIDEO:
return MediaFormat.createVideoFormat(format.id, mediaMimeType, format.bitrate,
MediaFormat.NO_VALUE, durationUs, format.width, format.height, null);
case AdaptationSet.TYPE_AUDIO:
return MediaFormat.createAudioFormat(format.id, mediaMimeType, format.bitrate,
MediaFormat.NO_VALUE, durationUs, format.audioChannels, format.audioSamplingRate, null,
format.language);
case AdaptationSet.TYPE_TEXT:
return MediaFormat.createTextFormat(format.id, mediaMimeType, format.bitrate,
durationUs, format.language);
default:
return null;
}
}
示例9: parseEAc3AnnexFFormat
import com.google.android.exoplayer.MediaFormat; //导入依赖的package包/类
/**
* Returns the E-AC-3 format given {@code data} containing the EC3SpecificBox according to
* ETSI TS 102 366 Annex F. The reading position of {@code data} will be modified.
*
* @param data The EC3SpecificBox to parse.
* @param trackId The track identifier to set on the format, or null.
* @param durationUs The duration to set on the format, in microseconds.
* @param language The language to set on the format.
* @return The E-AC-3 format parsed from data in the header.
*/
public static MediaFormat parseEAc3AnnexFFormat(ParsableByteArray data, String trackId,
long durationUs, String language) {
data.skipBytes(2); // data_rate, num_ind_sub
// Read only the first substream.
// TODO: Read later substreams?
int fscod = (data.readUnsignedByte() & 0xC0) >> 6;
int sampleRate = SAMPLE_RATE_BY_FSCOD[fscod];
int nextByte = data.readUnsignedByte();
int channelCount = CHANNEL_COUNT_BY_ACMOD[(nextByte & 0x0E) >> 1];
if ((nextByte & 0x01) != 0) { // lfeon
channelCount++;
}
return MediaFormat.createAudioFormat(trackId, MimeTypes.AUDIO_E_AC3, MediaFormat.NO_VALUE,
MediaFormat.NO_VALUE, durationUs, channelCount, sampleRate, null, language);
}
示例10: adaptiveTrack
import com.google.android.exoplayer.MediaFormat; //导入依赖的package包/类
@Override
public void adaptiveTrack(SmoothStreamingManifest manifest, int element, int[] trackIndices) {
if (adaptiveFormatEvaluator == null) {
// Do nothing.
return;
}
MediaFormat maxHeightMediaFormat = null;
StreamElement streamElement = manifest.streamElements[element];
int maxWidth = -1;
int maxHeight = -1;
Format[] formats = new Format[trackIndices.length];
for (int i = 0; i < formats.length; i++) {
int manifestTrackIndex = trackIndices[i];
formats[i] = streamElement.tracks[manifestTrackIndex].format;
MediaFormat mediaFormat = initManifestTrack(manifest, element, manifestTrackIndex);
if (maxHeightMediaFormat == null || mediaFormat.height > maxHeight) {
maxHeightMediaFormat = mediaFormat;
}
maxWidth = Math.max(maxWidth, mediaFormat.width);
maxHeight = Math.max(maxHeight, mediaFormat.height);
}
Arrays.sort(formats, new DecreasingBandwidthComparator());
MediaFormat adaptiveMediaFormat = maxHeightMediaFormat.copyAsAdaptive(null);
tracks.add(new ExposedTrack(adaptiveMediaFormat, element, formats, maxWidth, maxHeight));
}
示例11: parsePayload
import com.google.android.exoplayer.MediaFormat; //导入依赖的package包/类
@Override
protected void parsePayload(ParsableByteArray data, long timeUs) {
int packetType = data.readUnsignedByte();
// Parse sequence header just in case it was not done before.
if (packetType == AAC_PACKET_TYPE_SEQUENCE_HEADER && !hasOutputFormat) {
byte[] audioSpecifiConfig = new byte[data.bytesLeft()];
data.readBytes(audioSpecifiConfig, 0, audioSpecifiConfig.length);
Pair<Integer, Integer> audioParams = CodecSpecificDataUtil.parseAacAudioSpecificConfig(
audioSpecifiConfig);
MediaFormat mediaFormat = MediaFormat.createAudioFormat(null, MimeTypes.AUDIO_AAC,
MediaFormat.NO_VALUE, MediaFormat.NO_VALUE, getDurationUs(), audioParams.second,
audioParams.first, Collections.singletonList(audioSpecifiConfig), null);
output.format(mediaFormat);
hasOutputFormat = true;
} else if (packetType == AAC_PACKET_TYPE_AAC_RAW) {
// Sample audio AAC frames
int bytesToWrite = data.bytesLeft();
output.sampleData(data, bytesToWrite);
output.sampleMetadata(timeUs, C.SAMPLE_FLAG_SYNC, bytesToWrite, 0, null);
}
}
示例12: getAllTracks
import com.google.android.exoplayer.MediaFormat; //导入依赖的package包/类
private List<TvTrackInfo> getAllTracks() {
String trackId;
List<TvTrackInfo> tracks = new ArrayList<>();
int[] trackTypes = {
DemoPlayer.TYPE_AUDIO,
DemoPlayer.TYPE_VIDEO,
DemoPlayer.TYPE_TEXT
};
for (int trackType : trackTypes) {
int count = mPlayer.getTrackCount(trackType);
for (int i = 0; i < count; i++) {
MediaFormat format = mPlayer.getTrackFormat(trackType, i);
trackId = getTrackId(trackType, i);
TvTrackInfo.Builder builder = new TvTrackInfo.Builder(trackType, trackId);
if (trackType == DemoPlayer.TYPE_VIDEO) {
builder.setVideoWidth(format.width);
builder.setVideoHeight(format.height);
} else if (trackType == DemoPlayer.TYPE_AUDIO) {
builder.setAudioChannelCount(format.channelCount);
builder.setAudioSampleRate(format.sampleRate);
if (format.language != null) {
builder.setLanguage(format.language);
}
} else if (trackType == DemoPlayer.TYPE_TEXT) {
if (format.language != null) {
builder.setLanguage(format.language);
}
}
tracks.add(builder.build());
}
}
return tracks;
}
示例13: setQuality
import com.google.android.exoplayer.MediaFormat; //导入依赖的package包/类
@Override public void setQuality(View v) {
PopupMenu popup = new PopupMenu(activity, v);
popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
@Override public boolean onMenuItemClick(MenuItem item) {
player.setSelectedTrack(0, (item.getItemId() - 1));
return false;
}
});
ArrayList<Integer> formats = new ArrayList<>();
Menu menu = popup.getMenu();
menu.add(Menu.NONE, 0, 0, "Bitrate");
for (int i = 0; i < player.getTrackCount(0); i++) {
MediaFormat format = player.getTrackFormat(0, i);
if (MimeTypes.isVideo(format.mimeType)) {
Log.e("dsa", format.bitrate + "");
if (format.adaptive) {
menu.add(1, (i + 1), (i + 1), "Auto");
} else {
if (!formats.contains(format.bitrate)) {
menu.add(1, (i + 1), (i + 1), (format.bitrate) / 1000 + " kbps");
formats.add(format.bitrate);
}
}
}
}
menu.setGroupCheckable(1, true, true);
menu.findItem((player.getSelectedTrack(0) + 1)).setChecked(true);
popup.show();
}
示例14: onPlayerStateChanged
import com.google.android.exoplayer.MediaFormat; //导入依赖的package包/类
@Override
public void onPlayerStateChanged(boolean playWhenReady, int state) {
if (mListener == null) {
return;
}
mListener.onStateChanged(playWhenReady, state);
if (state == ExoPlayer.STATE_READY && mPlayer.getTrackCount(TRACK_TYPE_VIDEO) > 0
&& playWhenReady) {
MediaFormat format = mPlayer.getTrackFormat(TRACK_TYPE_VIDEO, 0);
mListener.onVideoSizeChanged(format.width,
format.height, format.pixelWidthHeightRatio);
}
}
示例15: prepare
import com.google.android.exoplayer.MediaFormat; //导入依赖的package包/类
@Override
public boolean prepare() throws IOException {
if(!mSampleExtractor.prepare()) {
return false;
}
List<MediaFormat> formats = mSampleExtractor.getTrackFormats();
int trackCount = formats.size();
mTrackFormats.clear();
mReachedEos.clear();
for (int i = 0; i < trackCount; ++i) {
mTrackFormats.add(formats.get(i));
mReachedEos.add(false);
String mime = formats.get(i).mimeType;
if (MimeTypes.isVideo(mime) && mVideoTrackIndex == -1) {
mVideoTrackIndex = i;
if (android.media.MediaFormat.MIMETYPE_VIDEO_MPEG2.equals(mime)) {
mCcParser = new Mpeg2CcParser();
} else if (android.media.MediaFormat.MIMETYPE_VIDEO_AVC.equals(mime)) {
mCcParser = new H264CcParser();
}
}
}
if (mVideoTrackIndex != -1) {
mCea708TextTrackIndex = trackCount;
}
if (mCea708TextTrackIndex >= 0) {
mTrackFormats.add(MediaFormat.createTextFormat(null, MIMETYPE_TEXT_CEA_708, 0,
mTrackFormats.get(0).durationUs, ""));
}
return true;
}