我找不到具有元数据支持的Exoplayer的数据源扩展。你能帮忙吗 我还没有找到
protected Boolean doInBackground(final String... args) {
try {
if (station.getRadiourl().endsWith(".m3u8")) {
String url = station.getRadiourl();
emAudioPlayer.setDataSource(context, Uri.parse(url));
emAudioPlayer.prepareAsync();
} else {
Uri uri;
uri = Uri.parse(station.getRadiourl());
Allocator allocator = new DefaultAllocator(BUFFER_SEGMENT_SIZE);
String userAgent = Util.getUserAgent(context, "ExoPlayerDemo");
OkHttpClient okHttpClient = new OkHttpClient();
DataSource dataSource = new DefaultUriDataSource(context, null,
new OkHttpDataSource(okHttpClient, userAgent, null, null, CacheControl.FORCE_NETWORK));
ExtractorSampleSource sampleSource = new ExtractorSampleSource(uri, dataSource, allocator,
BUFFER_SEGMENT_COUNT * BUFFER_SEGMENT_SIZE);
MediaCodecAudioTrackRenderer audioRenderer = new MediaCodecAudioTrackRenderer(sampleSource,
MediaCodecSelector.DEFAULT, null, true, null, null,
AudioCapabilities.getCapabilities(context), AudioManager.STREAM_MUSIC);
exoPlayer.prepare(audioRenderer);
}
return true;
} catch (IllegalArgumentException e1) {
} catch (SecurityException e1) {
} catch (IllegalStateException e1) {
}
return false;
}
但我无法找到有关如何获取艺术家和当前歌曲名称等元数据的任何信息。是否有可能获得此类信息? 非常感谢。
答案 0 :(得分:0)
如果要获取歌手姓名,当前歌曲名称...,请使用此库:
implementation 'com.vodyasov:amr:0.5'
示例:
Uri uri = Uri.parse("URL");
OnNewMetadataListener ilistener = new OnNewMetadataListener() {
@Override
public void onNewHeaders(String stringUri, List<String> name, List<String> desc, List<String> br, List<String> genre, List<String> info) {
}
@Override
public void onNewStreamTitle(String stringUri, String streamTitle) {
Animation a = AnimationUtils.loadAnimation(MainActivity.this, R.anim.textanim);
a.reset();
songinfo.setText("Song : " + streamTitle);
}
};