0

別のスレッドでデバイスで再生する必要がある Mp3Link があります

私はこれを試しましたが、コードを実行すると、音楽を再生できません。誰か私のコードを見てください。何が間違っていましたか?

ここに私のコード:

Thread trd = new Thread(new Runnable(){
    public void run(){
        //code to do the HTTP request
        MediaPlayer mediaPlayer = new MediaPlayer();  
        mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);  
        try {  
            mediaPlayer.setDataSource(mp3Link);  
        } catch (IllegalArgumentException e) {  
            e.printStackTrace();  
        } catch (SecurityException e) {  
            e.printStackTrace();  
        } catch (IllegalStateException e) {  
            e.printStackTrace();  
        } catch (IOException e) {  
            e.printStackTrace();  
        }  
        mediaPlayer.prepareAsync();  
        // You can show progress dialog here untill it prepared to play  
        mediaPlayer.setOnPreparedListener(new OnPreparedListener() {  
            public void onPrepared(MediaPlayer mp) {  
                // Now dismis progress dialog, Media palyer will start playing 
                Log.d("Mediaplyer>>>>>>>>", "Mediaplyer>>>>>>>>");
                mp.start();  
            }  
        });  
        mediaPlayer.setOnErrorListener(new OnErrorListener() {  
            public boolean onError(MediaPlayer mp, int what, int extra) {  
                // dissmiss progress bar here. It will come here when  
                // MediaPlayer  
                // is not able to play file. You can show error message to user  
                return false;  
            }  
        });  

    }
});
trd.start();
4

1 に答える 1