1. 程式人生 > >安卓播放assets下的音樂檔案

安卓播放assets下的音樂檔案

mpMediaPlayer = new MediaPlayer(); AssetManager am = getAssets(); try { mpMediaPlayer.setDataSource(am.openFd("ktv.mp3").getFileDescriptor()); mpMediaPlayer.prepare(); mpMediaPlayer.start(); } catch (IllegalArgumentException 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(); }