Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Load sound from memory in Android

Is there any way to load a sound samples from memory using SoundPool.load method?

Unfortunatelly, all methods provided in SoundPool are using arguments for real files. The problem is that I want to load sounds from zip file on SDcard, and extracting zip (like in this solution) is not an option.

Furthermore, there is a solution for loading from uncomressed zip files, but my files is comressed (and will be with password).

So is there any way to have java.io.FileDescriptor that represents a virtual file, so I can implement some abstract class placing my own streams?

Best regards.

like image 984
desertkun Avatar asked Nov 10 '14 13:11

desertkun


1 Answers

I got the final answer on this question. This is feature-missing on Android platform. Android media playback framework doesn't support it for a very long time. Google also notices it, so Android6.0(API Level23) introduces android.media.MediaDataSource which could be used as a pure memory byte-array data source. Before API Level23, we still need to copy the memory data to a temporary file in the file system.

The following URL provide some more clues on this issue, its explanation is correct for both audio and video: how to play video from byte array in media player

like image 89
Clock ZHONG Avatar answered Sep 20 '22 13:09

Clock ZHONG