制作 Unity Android Native Media Player 插件

Making a Unity Android Native Media Player plugin

我正在为统一制作原生 android 媒体播放器插件,一切正常,插件加载正确,参数正确传递给插件,甚至播放器启动,但似乎什么都没有正在播放,没有声音 out.the 源代码是:

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);
    }
}
        }

好的,经过一些修改我更改了我的代码,现在它作为一个基本的整体工作 android 本地媒体播放器 plugin.here 的代码:

package com.bluedreamcatcher.nativemediaplayerplugin;

import android.media.AudioManager;
import android.media.MediaPlayer;
import android.media.MediaPlayer.OnPreparedListener;
import android.util.Log;

public class NativeMediaPlayer {
public MediaPlayer mediaPlayer;
public void StreamMedia(String URL) {
    Log.d("Unity",URL);
     mediaPlayer = new MediaPlayer();
    try {
        mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
        mediaPlayer.setDataSource(URL);
        mediaPlayer.prepareAsync();

    } catch (Exception eX) {
        String error;
        error = eX.toString();
        Log.d("Unity",error);

    }
    mediaPlayer.setOnPreparedListener(new OnPreparedListener() {
        public void onPrepared(MediaPlayer mp) {
            mp.start();
        }
    });

}

}