0

让我的代码工作。只是有一个部分有点麻烦。

    public void picksound(){

Intent mIntent = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Audio.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(mIntent, 1);
}


 public void onActivityResult(int requestCode, int resultCode, Intent mIntent) {
if (resultCode == RESULT_OK && null != mIntent) {
    if (requestCode == 1) {

            Uri selectedRing = mIntent.getData();

    }
}}

private void playSong(String selectedRing){
    MediaPlayer mp = new MediaPlayer();
    try {
        mp.setDataSource(selectedRing);
    } catch (IllegalArgumentException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (SecurityException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IllegalStateException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    try {
        mp.prepare();
    } catch (IllegalStateException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    mp.start(); 
}


public void alarmmsg(){
    //ringtone player
    playSong(selectedRing);
    //

这就是我正在使用的代码。当我尝试调用 playSong 函数时,我被要求输入一个字符串,它似乎接受的唯一字符串是“null”。有人可以帮忙看看我做错了什么吗?

4

1 回答 1

0

尝试更改此行:

MediaPlayer mp = new MediaPlayer();

对此:

MediaPlayer player = MediaPlayer.create(this, Uri.parse("http://www.urltofile.com/file.mp3"));
于 2012-11-20T11:39:55.380 回答