MediaPlayerのマニュアルには、以下のように書いてあります。
> public static MediaPlayer create(Context context, Uri uri)
> Convenience method to create a MediaPlayer for a given Uri. On success, prepare() will already have been called and must not be called again.
http://code.google.com/intl/ja-JP/android/reference/android/media/MediaPlayer.html
createが成功した時には,prepareは既に呼び出されているため,呼ぶ必要は有りません。
M5での API変更のドキュメントには
> MediaPlayer.prepare() is now called from MediaPlayer.create() and you will get an exception if you call MediaPlayer.prepare() after using create().
prepareは createから呼び出されるように変更されました。その為,createを利用した後に prepareを呼び出すと例外が発生し
ます。
どうしても、prepareを呼び出したい時には,
> public void prepare()
> Call this after setDataSource() or stop(), and before any other method that might throw IllegalStateException in this class
とありますので、setDataSourceもしくは stopを呼び出す必要があるようですね。
ソースコードを見てみると,MediaPlayerの状態が MEDIA_PLAYER_INITIALIZEDもしくは
MEDIA_PLAYER_STOPPEDでない場合には INVALID_OPERATIONを prepareが返しています。
--
ながまつ
On 12月23日, 午後12:52, hkoba <
miruru...@gmail.com> wrote:
> 小林と申します。
> MediaPlayerを使用して、mp3ファイルを再生しようとしましたが、上手く再生されませんでした。
>
> デバッグの為に、「adb logcat -d」を実行して確認しましたところ、prepare()を実行した際に、
> 「prepareAsync called in state 1」というステータスが入っておりました。
> こちら、何が影響しているのでしょうか...。
>
> ソースは、以下になりまして、mp3ファイルは、サンプルで動いていたものを利用しても、同じ結果となりました。
> 「prepareAsync called in state 1」で調べたのですが、あまり情報がなく、かつ、失敗例が少ないため、
> 行き詰ってしまいました...。