开发者

Android MediaPlayer - exception thrown from setdatasource native method

the following code i am using for playing

MediaPlayer mp3;
mp3=new MediaPlayer();
mp3.setDataSource("/beep.mp3");
mp3.start();

exception is thrown from setdatasou开发者_开发技巧rce native method

can anyone help me in this problem


Just put your file in asset folder n apply this code..

Media Player mp = new MediaPlayer();    

AssetFileDescriptor descriptor = contex.getAssets().openFd(fileName);
    mp.setDataSource( descriptor.getFileDescriptor(), 
descriptor.getStartOffset(), descriptor.getLength() );
    descriptor.close();
mp.prepare();
        mp.start();


  1. check your file path, or use FileDescriptor
  2. dont forgot prepare before start
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜