1

我有播放mp3的Android应用程序,但它根本不播放。我在许多设备上进行了测试,但我不知道为什么它不起作用。请任何人帮助解决这个问题。

 public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_elaraby_group);

     WebView wv=(WebView) findViewById(R.id.web_engine);

     wv = new WebView(this); 
     wv.setWebViewClient(new WebViewClient() );
     { 
         setContentView(wv); 
     wv.getSettings().setJavaScriptEnabled(true); 
     wv.loadUrl("file:///android_asset/index.html");
     audioPlayer();
     }


}
public void audioPlayer()
{
    //set up MediaPlayer    
    MediaPlayer mp = new MediaPlayer();

    try {
        mp.setDataSource("file:///android_asset/Azan.mp3");
        mp.prepare();
        mp.start();
    } catch (Exception e) {
        e.printStackTrace();
    }
}
4

1 回答 1

0

Assuming "Azan.mp3" is sitting in your /assets/ folder, try changing audioPlayer() to:

public void audioPlayer() {
    //set up MediaPlayer    
    MediaPlayer mp = new MediaPlayer();

    try {
        AssetFileDescriptor descriptor = getAssets().openFd("Azan.mp3");
        mp.setDataSource(descriptor.getFileDescriptor(), descriptor.getStartOffset(), descriptor.getLength());
        descriptor.close();
        mp.prepare();
        mp.start();
    } catch (Exception e) {
        e.printStackTrace();
    }
}
于 2013-06-16T08:25:57.167 回答