Load sound from memory in Android

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

Unfortunately, all methods provided in SoundPool use arguments for real files. The problem is that I want to upload sounds from a zip file to an SDcard, and extracting a zip (as in this solution) is not an option.

In addition, there is a solution for downloading from uncompressed zip files, but my files will change (and will be with a password).

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

Sincerely.

+7
java android memory zip soundpool
source share
2 answers

I got the final answer to this question. This is the lack of features on the Android platform. The multimedia playback system for Android has not supported it for a very long time. Google also notices this, so Android6.0 (API Level23) introduces the file android.media.MediaDataSource, which can be used as a data source for a byte array of pure memory. Up to API Level23, we still need to copy the memory data to a temporary file in the file system.

The following URL contains additional information about this problem, its explanation is correct for both audio and video: how to play video from an array of bytes in a media player

+2
source share

I wanted to suggest that you use MemoryFile, but after checking, I found that MemoryFile does not have a getFileDescriptor () method, which means that we could not use it as a parameter in SoundPool.load (). But I found this post: what uses MemoryFile in android

One guy implemented MemoryFileUtil.getFileDescriptor (memFile), he places his codes there. If his codes really could work, this means that we could load a sound sample from memory using SoundPool.load (). The only problem is writing data to memory in this file. The following site shows how to write memory data (from the result of a SQLITE query) to a memory file: http://www.programcreek.com/java-api-examples/index.php?api=android.os.MemoryFile

I will give you updates after my test.

+1
source share

All Articles