我正在为统一制作一个原生 android 媒体播放器插件,一切正常,插件加载正确,参数正确传递给插件,即使播放器启动,但似乎什么都没有播放,没有声音出来。源代码是:
package com.bluedreamcatcher.nativemediaplayerplugin;
import android.media.AudioManager;
import android.media.MediaPlayer;
import android.os.AsyncTask;
import android.util.Log;
import java.io.IOException;
public class NativeMediaPlayer {
public MediaPlayer mediaPlayer;
public void StreamMedia(String URL) {
Log.d("Unity",URL);
mediaPlayer = new MediaPlayer();
mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
try {
mediaPlayer.setDataSource(URL);
mediaPlayer.prepareAsync();
try {
mediaPlayer.start();
}catch (Exception ex){
Log.d("Unity",ex.getMessage());
}
if(mediaPlayer.isPlaying()){
Log.d("Unity","playing");
}
} catch (Exception eX) {
String error;
error = eX.toString();
Log.d("Unity",error);
}
}
}