Hiya我试图使用以下流创建一个简单的无线电应用程序:http://lb.topradio.be/topradio.mp3。
目前我使用ExoMedia作为我的默认音频播放器
它具有永远不会被调用的setMetadataListener
方法,因为在Mp3Extractor
类中peekId3Data
方法进行了此检查。
if (scratch.readUnsignedInt24() != Id3Decoder.ID3_TAG) {
// Not an ID3 tag.
break;
}
然而,当我在VLC Media Player中抛出相同的流时,它能够成功地从流中获取元数据
这是如何工作的?
我可以使用自定义Extractor
复制此内容吗?
由于
答案 0 :(得分:0)
count
打开了一个问题。基本上,元数据通过标头传输,而不是在流本身传输。
我在Exoplayer repository取得了成功,虽然我有一些跟踪同步问题,因为在实际歌曲开始播放之前,流缓存和元数据已到达。
修改强>
RxJava实施:
private long icyMetaInt = 1000;
public void showStreamData() {
Log.d(TAG, "Show stream metadata");
streamService.getStreamData()
.subscribeOn(Schedulers.io())
.repeatWhen(delays -> delays.concatMap(metaIntDelay -> {
Log.d(TAG, "icyMetaDelay = " + icyMetaInt + "ms ");
return Observable.timer(icyMetaInt, TimeUnit.MILLISECONDS);
}))
.subscribe(new Observer<Response<ResponseBody>>() {
@Override
public void onSubscribe(Disposable disposable) {
Log.d(TAG, "OnSubscribe");
}
@Override
public void onNext(Response<ResponseBody> response) {
Log.d(TAG, "onNext - " + response);
if (response.isSuccessful()) {
InputStream stream = response.body().byteStream();
if (stream != null) {
icyMetaInt = Integer.parseInt(response.headers().get("icy-metaint"));
ByteArrayOutputStream baos = new ByteArrayOutputStream();
try {
long skipped = stream.skip(icyMetaInt);
while (skipped != icyMetaInt) {
skipped += stream.skip(icyMetaInt - skipped);
}
int symbolLength = stream.read();
int metaDataLength = symbolLength * 16;
if (metaDataLength > 0) {
for (int i = 0; i < metaDataLength; ++i) {
int metaDataSymbol = stream.read();
if (metaDataSymbol > 0) {
baos.write(metaDataSymbol);
}
}
String result = baos.toString()
.replace("StreamTitle=", "")
.replaceAll("'", "")
.replaceAll(";", "");
baos.reset();
Log.d(TAG, result);
runOnUiThread(() -> textView.setText(result));
Log.d(TAG, response.headers().get("ice-audio-info"));
Log.d(TAG, response.headers().get("icy-description"));
Log.d(TAG, response.headers().get("icy-genre"));
Log.d(TAG, response.headers().get("icy-name"));
Log.d(TAG, response.headers().get("icy-url"));
}
} catch (IOException e) {
onError(e);
Log.e(TAG, "Failed to obtain metadata");
} finally {
try {
baos.close();
stream.close();
} catch (IOException e) {
onError(e);
}
}
}
}
}
@Override
public void onError(Throwable throwable) {
Log.d(TAG, "onError");
throwable.printStackTrace();
}
@Override
public void onComplete() {
Log.d(TAG, "onComplete");
}
});
}
改造界面:
import io.reactivex.Observable;
import okhttp3.ResponseBody;
import retrofit2.Response;
import retrofit2.http.GET;
import retrofit2.http.Headers;
import retrofit2.http.Streaming;
public interface StreamService {
@GET("stream")
@Headers("Icy-MetaData:1")
@Streaming
Observable<Response<ResponseBody>> getStreamData();
}