gpt4 book ai didi

java - 为什么 MediaExtractor 卡在 setDataSource 上?

转载 作者:行者123 更新时间:2023-11-29 09:29:30 26 4
gpt4 key购买 nike

我正在尝试使用 ExoPlayer 播放 AAC 流。我遇到了与使用内置 MediaPlayer 时遇到的相同问题:在 KitCat 上启动需要 15 - 20 秒(其他版本可能也会发生同样的情况,但现在没有任何测试)。

在 ExoPlayer 上,我能够获得一些关于后台发生的事情的信息。

流程在 FrameworkSampleDataSource 上的 MediaExtractor.getDataSource() 上卡住,方法 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 也有类似的问题。这只发生在真实设备上,模拟器会立即启动。

最佳答案

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); ..

关于java - 为什么 MediaExtractor 卡在 setDataSource 上?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27905059/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com