android - 涉及 soundpool 的应用程序的 BpMemoryHeap 问题

标签 android soundpool

我创建了一个包含大约 600 个小 ogg 文件的应用程序。总计约15MB。每个文件都会有平均值。 6秒的声音。这不是游戏应用程序,而是 child 学习应用程序。

我尝试在媒体播放器上加载声音。一次运行良好,连续播放时我最终没有声音。它是空白的。

所以我尝试了声音池选项。声音仅在加载到 soundpool 加载器后才播放。因此我尝试在应用程序的启动时加载声音。因此,加载声音大约需要 30 秒,之后主屏幕就会显示(我在后台使用异步加载声音,进度条显示在前面)。

此设置适用于大约 450 个 ogg 文件,当我添加超过 450 个声音时,我在加载几个声音时遇到堆错误,并且应用程序强制关闭并出现以下错误:

 02-27 07:13:02.614: I/Choreographer(27172): Skipped 35 frames!  The application may be doing too much work on its main thread.
 02-27 07:13:11.012: E/IMemory(27172): binder=0x56f0c430 transaction failed fd=-2147483647, size=0, err=-2147483646 (Unknown error 2147483646)
 02-27 07:13:11.012: E/IMemory(27172): cannot dup fd=-2147483647, size=0, err=-2147483646 (Bad file number)
 02-27 07:13:11.012: E/IMemory(27172): cannot map BpMemoryHeap (binder=0x56f0c430), size=0, fd=-1 (Bad file number)
 02-27 07:13:11.020: W/dalvikvm(27172): threadid=37: thread exiting with uncaught exception (group=0x40d75930)
 02-27 07:13:11.153: E/IMemory(27172): cannot dup fd=818, size=1048576, err=0 (Too many open files)
 02-27 07:13:11.153: E/IMemory(27172): cannot map BpMemoryHeap (binder=0x56f09e80), size=1048576, fd=-1 (Bad file number)
 02-27 07:13:11.403: E/IMemory(27172): cannot dup fd=972, size=1048576, err=0 (Too many open files)
 02-27 07:13:11.403: E/IMemory(27172): cannot map BpMemoryHeap (binder=0x56f09988), size=1048576, fd=-1 (Bad file number)
 02-27 07:13:11.450: E/IMemory(27172): cannot dup fd=873, size=1048576, err=0 (Too many open files)
 02-27 07:13:11.450: E/IMemory(27172): cannot map BpMemoryHeap (binder=0x56f0a500), size=1048576, fd=-1 (Bad file number)
 02-27 07:13:11.520: E/IMemory(27172): cannot dup fd=954, size=1048576, err=0 (Too many open files)
 02-27 07:13:11.520: E/IMemory(27172): cannot map BpMemoryHeap (binder=0x56efbde8), size=1048576, fd=-1 (Bad file number)
 02-27 07:13:11.614: W/dalvikvm(27172): threadid=35: thread exiting with uncaught exception (group=0x40d75930)
 02-27 07:13:11.677: E/IMemory(27172): cannot dup fd=903, size=1048576, err=0 (Too many open files)
 02-27 07:13:11.677: E/IMemory(27172): cannot map BpMemoryHeap (binder=0x56f09b30), size=1048576, fd=-1 (Bad file number)
 02-27 07:13:11.716: E/IMemory(27172): cannot dup fd=978, size=1048576, err=0 (Too many open files)
 02-27 07:13:11.716: E/IMemory(27172): cannot map BpMemoryHeap (binder=0x5d99add0), size=1048576, fd=-1 (Bad file number) 
 02-27 07:13:11.747: E/IMemory(27172): cannot dup fd=941, size=1048576, err=0 (Too many open files)
 02-27 07:13:11.747: E/IMemory(27172): cannot map BpMemoryHeap (binder=0x56efb710), size=1048576, fd=-1 (Bad file number)
 02-27 07:13:11.809: E/IMemory(27172): cannot dup fd=991, size=1048576, err=0 (Too many open files)
 02-27 07:13:11.809: E/IMemory(27172): cannot map BpMemoryHeap (binder=0x56efaa90), size=1048576, fd=-1 (Bad file number)

如何解决这个问题?堆上的大部分问题与数据库游标有关,而不是与 soundpool 有关。

如果这个问题无法解决,当我要加载 600 个声音时,使用 soundpool 的解决方法是什么?

谢谢!

最佳答案

有了这么多文件,您将需要延迟加载它们并转储一段时间未使用的文件。

有一个 LruCache在 Android 中,这将为您提供帮助。

关于android - 涉及 soundpool 的应用程序的 BpMemoryHeap 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15102931/

相关文章:

android - 任务 ':app:packageDebug' 执行失败 - 无法读取 zip 文件

java - 如何更改从 PagerSlidingTabStrip 创建的选项卡标题的字体?

android - 如何查看安装在 Android 设备上的 SD 卡有多少可用空间?

安卓 : How to change Playback Rate of music using OpenSL ES

Android,在第一个 Activity 中加载mp3并在进一步的 Activity 中访问它

android - SoundPool 播放不工作

android - 何时注销在 onCreate 中注册的广播接收器?

android - 将 google cloud ml 与 Android 应用程序一起使用

java - android 媒体播放器的替代品?

Android - 如何在不停止 TimerTask 的情况下将 SoundPool 静音