Я пытаюсь воспроизвести медиа-файл (mp3) из файла расширения apk,
, но я попробовал все, и ничего не работает !!
Я думаю, что-то в библиотеке APKExpansionSupport
или ZipResourceFile
не работает должным образом ..
Для библиотек, которые я использовал, это:
implementation 'com.danikula.expansion:expansion:1.3.4'
implementation 'com.danikula.expansion:zip:1.2.1'
Вот мой код :
MediaPlayer mPlayer = new MediaPlayer();
mPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
ZipResourceFile expansionFile = null;
try {
expansionFile = APKExpansionSupport.getAPKExpansionZipFile(getBaseContext(),4,0);
AssetFileDescriptor afd = expansionFile.getAssetFileDescriptor("cities/test.mp3");
mPlayer.setDataSource(afd.getFileDescriptor(),afd.getStartOffset(),afd.getLength());
// Prepare media player
mPlayer.prepare();
} catch (Exception exc) {
// Show visible error toast
Toast.makeText(showSelectSound.this, exc.toString(), Toast.LENGTH_LONG).show();
}
mPlayer.start();
И я добавил это в Манифест. xml:
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />