我已经构建了exoplayer ffmpeg扩展并添加到我的项目中,因为我需要支持AMR格式,所以:
遵循教程:FFmpeg Extension
COMMON_OPTIONS="\
...
--enable-decoder=amrnb \
--enable-decoder=amrwb \
...
编译步骤后:
cd "${FFMPEG_EXT_PATH}"/jni && \
${NDK_PATH}/ndk-build APP_ABI="armeabi-v7a arm64-v8a x86" -j4
我用:
生成了aar文件./gradlew :extensions-ffmpeg:assembleDebug
所以我生成了 extension-ffmpeg-debug.arr 文件并将其放在我项目的lib文件夹中。
我的播放器实施:
public class DefaultPlayer {
private ExoPlayer player;
//"flac" "amr" "wma" "wav" "3gp" "mp3"
public DefaultPlayer(Context context) {
DefaultBandwidthMeter bandwidthMeter = new DefaultBandwidthMeter();
playerInit(context, bandwidthMeter);
try {
testFormat(context);
} catch (RawResourceDataSource.RawResourceDataSourceException e) {
e.printStackTrace();
}
}
private void testFormat(Context context) throws RawResourceDataSource.RawResourceDataSourceException {
Uri uri = RawResourceDataSource.buildRawResourceUri(R.raw.sample_flac);
final RawResourceDataSource dataSource = new RawResourceDataSource(context);
dataSource.open(new DataSpec(uri));
DefaultExtractorsFactory extractorsFactory = new DefaultExtractorsFactory();
ExtractorMediaSource mediaSource = new ExtractorMediaSource(uri, new DataSource.Factory() {
@Override
public DataSource createDataSource() {
return dataSource;
}
}, extractorsFactory, null, null);
player.prepare(mediaSource);
player.setPlayWhenReady(true);
}
private void playerInit(Context context, DefaultBandwidthMeter bandwidthMeter) {
TrackSelection.Factory videoTrackSelectionFactory = new AdaptiveTrackSelection.Factory(bandwidthMeter);
TrackSelector trackSelector = new DefaultTrackSelector(videoTrackSelectionFactory);
player = ExoPlayerFactory.newSimpleInstance(context, trackSelector);
player.addListener(new PlayerEventListener());
}
}
错误:
08-04 16:03:53.405 10873-10918/br.com.andersonsilva.musicmodel E/ExoPlayerImplInternal: Source error.
com.google.android.exoplayer2.source.UnrecognizedInputFormatException: None of the available extractors (MatroskaExtractor, FragmentedMp4Extractor, Mp4Extractor, Mp3Extractor, AdtsExtractor, Ac3Extractor, TsExtractor, FlvExtractor, OggExtractor, PsExtractor, WavExtractor, FlacExtractor) could read the stream.
at com.google.android.exoplayer2.source.ExtractorMediaPeriod$ExtractorHolder.selectExtractor(ExtractorMediaPeriod.java:774)
at com.google.android.exoplayer2.source.ExtractorMediaPeriod$ExtractingLoadable.load(ExtractorMediaPeriod.java:697)
at com.google.android.exoplayer2.upstream.Loader$LoadTask.run(Loader.java:315)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607)
at java.lang.Thread.run(Thread.java:761)
08-04 16:03:53.406 10873-10873/br.com.andersonsilva.musicmodel D/MUSIC: event: PlayerErrorEvent{error=com.google.android.exoplayer2.ExoPlaybackException}
08-04 16:03:53.407 10873-10873/br.com.andersonsilva.musicmodel D/MUSIC: event: PlayerStateChangedEvent{playWhenReady=true, playbackState=1}
还应该配置什么来运行AMR格式,有没有人有任何建议?