我正在尝试使用ExoPlayer播放AAC流。我遇到了使用内置MediaPlayer时遇到的同样问题:在KitCat上启动需要15 - 20秒(可能在其他版本上也是如此,但现在没有任何测试)。
在ExoPlayer上,我能够获得有关背景情况的一些信息。
流量卡在MediaExtractor.getDataSource()
FrameworkSampleDataSource
上,方法prepare
extractor = new MediaExtractor();
extractor.setDataSource(context, uri, headers);
日志提到了readAt
方法
01-12 12:07:03.458 4537-4584/com.example.claudio.exopla I/NuCachedSource2﹕ mDisconnectAtHighwatermark = 0, cacheConfig is NULL(1)
01-12 12:07:03.463 4537-4584/com.example.claudio.exopla I/NuCachedSource2﹕ readAt: mIsMetadataRetriever == 0
01-12 12:07:03.463 4537-4615/com.example.claudio.exopla I/ChromiumHTTPDataSource﹕ readAt offset =0 , mCurrentOffset = 0 size = 65536
01-12 12:07:04.298 4537-4615/com.example.claudio.exopla D/HTTPBase﹕ [1] Network BandWidth = 0 Kbps
01-12 12:07:04.298 4537-4615/com.example.claudio.exopla D/NuCachedSource2﹕ Remaining (64K), HighWaterThreshold (20480)
01-12 12:07:04.298 4537-4584/com.example.claudio.exopla I/NuCachedSource2﹕ readAt: waiting end ( player case )
01-12 12:07:04.298 4537-4615/com.example.claudio.exopla I/ChromiumHTTPDataSource﹕ readAt offset =65536 , mCurrentOffset = 65536 size = 65536
01-12 12:07:04.298 4537-4584/com.example.claudio.exopla V/ChromiumHTTPDataSource﹕ mContentSize is undefined or network might be disconnected
01-12 12:07:04.298 4537-4584/com.example.claudio.exopla V/ChromiumHTTPDataSource﹕ mContentSize is undefined or network might be disconnected
01-12 12:07:04.323 4537-4584/com.example.claudio.exopla I/NuCachedSource2﹕ readAt: mIsMetadataRetriever == 0
01-12 12:07:06.328 4537-4584/com.example.claudio.exopla I/NuCachedSource2﹕ readAt: waiting end ( player case )
01-12 12:07:06.328 4537-4584/com.example.claudio.exopla E/NuCachedSource2﹕ readAt:Timeout ( player case )
01-12 12:07:06.328 4537-4584/com.example.claudio.exopla I/NuCachedSource2﹕ readAt: mIsMetadataRetriever == 0
01-12 12:07:08.328 4537-4584/com.example.claudio.exopla I/NuCachedSource2﹕ readAt: waiting end ( player case )
01-12 12:07:08.328 4537-4584/com.example.claudio.exopla E/NuCachedSource2﹕ readAt:Timeout ( player case )
01-12 12:07:08.328 4537-4584/com.example.claudio.exopla I/NuCachedSource2﹕ readAt: mIsMetadataRetriever == 0
01-12 12:07:10.328 4537-4584/com.example.claudio.exopla I/NuCachedSource2﹕ readAt: waiting end ( player case )
01-12 12:07:10.328 4537-4584/com.example.claudio.exopla E/NuCachedSource2﹕ readAt:Timeout ( player case )
01-12 12:07:10.328 4537-4584/com.example.claudio.exopla I/NuCachedSource2﹕ readAt: mIsMetadataRetriever == 0
01-12 12:07:12.328 4537-4584/com.example.claudio.exopla I/NuCachedSource2﹕ readAt: waiting end ( player case )
01-12 12:07:12.328 4537-4584/com.example.claudio.exopla E/NuCachedSource2﹕ readAt:Timeout ( player case )
01-12 12:07:12.328 4537-4584/com.example.claudio.exopla I/NuCachedSource2﹕ readAt: mIsMetadataRetriever == 0
01-12 12:07:14.328 4537-4584/com.example.claudio.exopla I/NuCachedSource2﹕ readAt: waiting end ( player case )
01-12 12:07:14.328 4537-4584/com.example.claudio.exopla E/NuCachedSource2﹕ readAt:Timeout ( player case )
01-12 12:07:14.328 4537-4584/com.example.claudio.exopla I/NuCachedSource2﹕ readAt: mIsMetadataRetriever == 0
01-12 12:07:16.328 4537-4584/com.example.claudio.exopla I/NuCachedSource2﹕ readAt: waiting end ( player case )
01-12 12:07:16.328 4537-4584/com.example.claudio.exopla E/NuCachedSource2﹕ readAt:Timeout ( player case )
01-12 12:07:16.328 4537-4584/com.example.claudio.exopla I/NuCachedSource2﹕ readAt: mIsMetadataRetriever == 0
01-12 12:07:18.328 4537-4584/com.example.claudio.exopla I/NuCachedSource2﹕ readAt: waiting end ( player case )
01-12 12:07:18.328 4537-4584/com.example.claudio.exopla E/NuCachedSource2﹕ readAt:Timeout ( player case )
01-12 12:07:18.328 4537-4584/com.example.claudio.exopla I/NuCachedSource2﹕ readAt: mIsMetadataRetriever == 0
01-12 12:07:18.413 4537-4615/com.example.claudio.exopla D/HTTPBase﹕ [2] Network BandWidth = 70 Kbps
01-12 12:07:18.413 4537-4615/com.example.claudio.exopla D/NuCachedSource2﹕ Remaining (127K), HighWaterThreshold (20480)
01-12 12:07:18.413 4537-4615/com.example.claudio.exopla D/NuCachedSource2﹕ readInternal - late!!!
01-12 12:07:18.418 4537-4584/com.example.claudio.exopla I/NuCachedSource2﹕ readAt: waiting end ( player case )
01-12 12:07:18.418 4537-4615/com.example.claudio.exopla I/ChromiumHTTPDataSource﹕ readAt offset =131072 , mCurrentOffset = 131072 size = 65536
01-12 12:07:18.423 4537-4584/com.example.claudio.exopla E/tmiMPEG2TSExtractor﹕ SnifftmiMPEG2TS @LINE=1372
我认为这可能与缓冲有关,因为MediaPlayer有类似的问题。这只发生在真实设备上,模拟器立即启动。
答案 0 :(得分:-1)
1)完成使用 MediaExtractor 后再次使用null。
MediaExtractor extractor = new MediaExtractor();
extractor.setDataSource(...);
int numTracks = extractor.getTrackCount();
for (int i = 0; i < numTracks; ++i) {
MediaFormat format = extractor.getTrackFormat(i);
String mime = format.getString(MediaFormat.KEY_MIME);
if (weAreInterestedInThisTrack) {
extractor.selectTrack(i);
}
}
ByteBuffer inputBuffer = ByteBuffer.allocate(...)
while (extractor.readSampleData(inputBuffer, ...) >= 0) {
int trackIndex = extractor.getSampleTrackIndex();
long presentationTimeUs = extractor.getSampleTime();
...
extractor.advance();
}
extractor.release();
extractor = null;
2)
MediaExtractor extractor= new MediaExtractor();
File file = new File(this.fileName);
extractor.setDataSource(this.fileName);
int tracks = extractor.getTrackCount();
extractor.selectTrack(0); ..