此类JCAudio
public JcAudio(String title, String path, Origin origin) {
this.id = -1;
this.position = -1;
this.title = title;
this.path = path;
this.origin = origin;
}
public static JcAudio createFromFilePath(String title, String filePath) {
return new JcAudio(title, filePath, Origin.FILE_PATH);
}
主要活动
recyclerView = (RecyclerView) findViewById(R.id.recyclerView);
player = (JcPlayerView) findViewById(R.id.jcplayer);
ZipResourceFile expansionFile = null;
try {
expansionFile = APKExpansionSupport.getAPKExpansionZipFile(this, 3, 0);
} catch (IOException e) {
e.printStackTrace();
}
if (expansionFile != null) {
ZipResourceFile.ZipEntryRO[] fd = expansionFile.getAllEntries();
String oldsong = fd[0].mFileName;
ArrayList<JcAudio> jcAudios = new ArrayList<>();
jcAudios.add(JcAudio.createFromFilePath("Old Song", fd[0].mFile.getAbsolutePath() + "/" + oldsong));
player.initPlaylist(jcAudios);
player.registerInvalidPathListener(this);
player.registerStatusListener(this);
adapterSetup();
我尝试播放mp3为什么我不能从obb文件播放mp3?我的代码有什么问题?任何人都可以帮助我吗?
我从android studio中筛选出详细信息
05-31 20:37:52.407 29286-29286/com.tjcorp.tonykeane.song W/System.err: com.tjcorp.tonykeane.song.tjplayer.JcPlayerExceptions.AudioFilePathInvalidException: The file path is not a valid path: /storage/emulated/0/Android/obb/com.tjcorp.tonykeane.song/main.3.com.tjcorp.tonykeane.song.obb/oldsong.mp3
05-31 20:37:52.407 29286-29286/com.tjcorp.tonykeane.song W/System.err: Have you add File Access Permission?
05-31 20:37:52.408 29286-29286/com.tjcorp.tonykeane.song W/System.err: at com.tjcorp.tonykeane.song.tjplayer.JcPlayerService.throwError(JcPlayerService.java:320)
05-31 20:37:52.408 29286-29286/com.tjcorp.tonykeane.song W/System.err: at com.tjcorp.tonykeane.song.tjplayer.JcPlayerService.play(JcPlayerService.java:236)
05-31 20:37:52.408 29286-29286/com.tjcorp.tonykeane.song W/System.err: at com.tjcorp.tonykeane.song.tjplayer.JcAudioPlayer.playAudio(JcAudioPlayer.java:85)
05-31 20:37:52.408 29286-29286/com.tjcorp.tonykeane.song W/System.err: at com.tjcorp.tonykeane.song.tjplayer.JcPlayerView.playAudio(JcPlayerView.java:347)
05-31 20:37:52.408 29286-29286/com.tjcorp.tonykeane.song W/System.err: at com.tjcorp.tonykeane.song.HomeActivity$1.onItemClick(HomeActivity.java:272)
05-31 20:37:52.408 29286-29286/com.tjcorp.tonykeane.song W/System.err: at com.tjcorp.tonykeane.song.AudioAdapter$AudioAdapterViewHolder$1.onClick(AudioAdapter.java:133)
05-31 20:37:52.408 29286-29286/com.tjcorp.tonykeane.song W/System.err: at android.view.View.performClick(View.java:5207)
05-31 20:37:52.408 29286-29286/com.tjcorp.tonykeane.song W/System.err: at android.view.View$PerformClick.run(View.java:21177)
05-31 20:37:52.408 29286-29286/com.tjcorp.tonykeane.song W/System.err: at android.os.Handler.handleCallback(Handler.java:739)
05-31 20:37:52.409 29286-29286/com.tjcorp.tonykeane.song W/System.err: at android.os.Handler.dispatchMessage(Handler.java:95)
05-31 20:37:52.409 29286-29286/com.tjcorp.tonykeane.song W/System.err: at android.os.Looper.loop(Looper.java:148)
05-31 20:37:52.409 29286-29286/com.tjcorp.tonykeane.song W/System.err: at android.app.ActivityThread.main(ActivityThread.java:5442)
05-31 20:37:52.409 29286-29286/com.tjcorp.tonykeane.song W/System.err: at java.lang.reflect.Method.invoke(Native Method)
05-31 20:37:52.409 29286-29286/com.tjcorp.tonykeane.song W/System.err: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:738)
05-31 20:37:52.409 29286-29286/com.tjcorp.tonykeane.song W/System.err: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:628)
我已经在Manifest.xml中授予权限访问权限,感谢您的帮助
当我在下面使用此代码时,我可以播放mp3,但我不知道如何添加到recycleview列表显示?如何将其改为arraylist
AssetFileDescriptor fd1 = expansionFile.getAssetFileDescriptor("oldsong.mp3");
MediaPlayer mediaPlayer = new MediaPlayer();
try {
mediaPlayer.setDataSource( fd.getFileDescriptor(),
fd.getStartOffset(),fd.getLength());
} catch (IOException e) {
e.printStackTrace();
}
try {
mediaPlayer.prepare();
} catch (IOException e) {
e.printStackTrace();
}
mediaPlayer.start();