React Native(Android)检测远程视频url上存在声音



我想创建一个原生的android模块来检测视频中是否存在音轨。现在我正在使用MediaPlayer,但没有调用onPrepared。我是不是错过了什么?本机模块也正确绑定。我的日志显示MediaPlayer: Couldn't open file on client side; trying server side: java.io.FileNotFoundException: No content provider: https://storage.googleapis.com/SPECIAL_FILE.mp4

public class RNSoundDetectionModule extends ReactContextBaseJavaModule {
private final ReactApplicationContext reactContext;
public RNSoundDetectionModule(ReactApplicationContext reactContext) {
super(reactContext);
this.reactContext = reactContext;
}
@ReactMethod
public void doesLocalVideoHaveAudioTrack(String path, Callback cb) {
boolean audioTrack =false;
MediaMetadataRetriever retriever = new MediaMetadataRetriever();
retriever.setDataSource(path);
String hasAudioStr = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_HAS_AUDIO);
if(hasAudioStr!=null && hasAudioStr.equals("yes")){
audioTrack=true; }
else{
audioTrack=false; }
try {
cb.invoke(audioTrack, null);
} catch (Exception e) {
cb.invoke(e.toString(), null);
}
}
@ReactMethod
public void getRemoteAudioTracks(String path, final Callback cb) {
try {
MediaPlayer mediaPlayer = new MediaPlayer();
mediaPlayer.setDataSource(path);
mediaPlayer.setOnPreparedListener(new MediaPlayer.OnPreparedListener(){
@Override
public void onPrepared(MediaPlayer mp) {
cb.invoke(mp.getTrackInfo(), null);
}
});
mediaPlayer.prepareAsync();
} catch (IOException e) {
cb.invoke(e.toString(), null);
}
}
@Override
public String getName() {
return "RNSoundDetection";
}
}

修复了它-请在此处查看我的库:https://github.com/evanjmg/react-native-sound-detection

相关内容

  • 没有找到相关文章

最新更新