2

約 600 の小さな ogg ファイルを含むアプリを作成しました。合計約15MB。各ファイルには平均があります。6秒の音。ゲームアプリではなく、お子様向けの学習アプリです。

メディアプレーヤーに音を読み込んでみました。一度は正常に動作し、連続して再生すると音が出なくなります。空白です。

そこで、サウンドプールオプションを試してみました。サウンドは、サウンドプールローダーにロードされた後にのみ再生されます。そのため、アプリの開始時にサウンドを読み込んでみました。そのため、サウンドのロードに約 30 秒かかり、その後メイン画面が表示されます (バックグラウンドで Async を使用してサウンドをロードしていて、プログレス バーが前面に表示されます)。

このセットアップは、450 を超えるサウンドを 1 つ追加すると、約 450 の ogg ファイルで問題なく機能します。いくつかのサウンドをロードするときにヒープ エラーが発生し、以下のエラーでアプリが強制終了します。

 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 あるときにサウンドプールを使用する際の回避策は何ですか?

ありがとう!

4

1 に答える 1

2

このように多くのファイルがあると、それらを遅延ロードし、しばらく使用されていないファイルをダンプしたくなるでしょう。

そこで役立つLruCacheがAndroidにあります。

于 2013-02-27T02:11:57.350 に答える