Java Android 5.0棒棒糖中的mediaPlayer,我无法播放,长音来自url。在安卓5.0问世之前,我从未遇到过问题

Java Android 5.0棒棒糖中的mediaPlayer,我无法播放,长音来自url。在安卓5.0问世之前,我从未遇到过问题,java,android,audio,callback,uri,Java,Android,Audio,Callback,Uri,我的日志 public void onClick(View v) { toSound.setVisibility(View.INVISIBLE); toPro.setVisibility(View.VISIBLE); toSound1 = toSound; toPro1 = toPro; if(isPLAYING){ mp.stop(); mp.reset(); } try{ isPLAY

我的日志

public void onClick(View v) {
    toSound.setVisibility(View.INVISIBLE);
    toPro.setVisibility(View.VISIBLE);
    toSound1 = toSound;
    toPro1 = toPro;

    if(isPLAYING){
        mp.stop();
        mp.reset();
    }

    try{
        isPLAYING = true;
        mp.setDataSource("http://..."
                + result.get(arg0).toCode
                +"&ie=UTF-8"
                + "&q="
                + result.get(arg0).toText);
        mp.prepareAsync();

    }catch(IOException e){
        Log.i("error", "prepare() failed");
    }
}



mp.setOnPreparedListener(new OnPreparedListener() {
    @Override
    public void onPrepared(MediaPlayer mp1) {
        mp.start();
        toPro1.setVisibility(View.INVISIBLE);
        toSound1.setVisibility(View.VISIBLE);
        fromPro1.setVisibility(View.INVISIBLE);
        fromSound1.setVisibility(View.VISIBLE);
    }
});
我在清单中有API级别21,并尝试使用

V/MediaPlayer(6196): setVideoSurfaceTexture
V/MediaPlayer(6196): prepareAsync
I/System.out(6196): KnoxVpnUidStorageknoxVpnSupported API value returned is false
D/MediaHTTPConnection(6196): setReadTimeout with 30000ms
I/System.out(6196): (HTTPLog)-Static: isSBSettingEnabled false
V/ActivityThread(6196): updateVisibility : ActivityRecord{27745ca2 token=android.os.BinderProxy@c738f70 show : true
D/MediaHTTPConnection(6196): setReadTimeout with 30000ms
I/System.out(6196): (HTTPLog)-Static: isSBSettingEnabled false
I/System.out(6196): KnoxVpnUidStorageknoxVpnSupported API value returned is false
D/MediaHTTPConnection(6196): setReadTimeout with 30000ms
I/System.out(6196): (HTTPLog)-Static: isSBSettingEnabled false
I/System.out(6196): KnoxVpnUidStorageknoxVpnSupported API value returned is false
D/MediaHTTPConnection(6196): setReadTimeout with 30000ms
I/System.out(6196): (HTTPLog)-Static: isSBSettingEnabled false
I/System.out(6196): KnoxVpnUidStorageknoxVpnSupported API value returned is false
V/MediaPlayer(6196): message received msg=100, ext1=1, ext2=-2147483648
E/MediaPlayer(6196): error (1, -2147483648)
V/MediaPlayer(6196): callback application
V/MediaPlayer(6196): back from callback
E/MediaPlayer(6196): Error (1,-2147483648)
V/MediaPlayer-JNI(6196): reset
V/MediaPlayer(6196): reset
V/MediaPlayer(6196): message received msg=8, ext1=0, ext2=0
V/MediaPlayer(6196): notify(8, 0, 0) callback on disconnected mediaplayer

在dependencies中添加下面的行

编译'com.loopj.android:android异步http:1.4.9'

然后在MainActivy中添加以下代码

SetDataSource(context,Uri.parse(your url))
现在运行应用程序,音乐将正常播放。谢谢

                try

                 {
                    KeyStore trustStore = KeyStore.getInstance(KeyStore.getDefaultType());
                    trustStore.load(null, null);
                    MySSLSocketFactory sf = new MySSLSocketFactory(trustStore);
                    sf.setHostnameVerifier(MySSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
                    sf.fixHttpsURLConnection();
                    HostnameVerifier hostnameVerifier = org.apache.http.conn.ssl.SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER;
                    HttpsURLConnection.setDefaultHostnameVerifier(hostnameVerifier);

                    mediaPlayer.setDataSource(MusicPlayerTestActivity.this, Uri.parse(urlFromServer)); // setup song from https://www.hrupin.com/wp-content/uploads/mp3/testsong_20_sec.mp3 URL to mediaplayer data source

                    mediaPlayer.prepare(); // you must call this method after setup the datasource in setDataSource method. After calling prepare() the instance of MediaPlayer starts load data from URL to internal buffer.
                    mediaPlayer.start();
                }
                catch (Exception e)
                {
                    e.printStackTrace();
                }