Advertisement
Guest User

Untitled

a guest
Oct 25th, 2016
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.91 KB | None | 0 0
  1. /*
  2. resourceに入ってる音声ファイルデータをMediaPlayerに取り込んで、
  3. 再生→停止→また最初から再生をやりたい
  4. 目的:Androidプログラミングの習熟
  5. ところが、seekToを実行するときにエラーが発生:
  6. E/MediaPlayer: Error (-38,0)
  7. E/MediaPlayer: start called in state 0
  8. E/MediaPlayer: error (-38, 0)
  9. E/MediaPlayer: Error (-38,0)
  10. 一体なぜ? 対処法は?
  11. */
  12. playerTwo = MediaPlayer.create(this, R.raw.song2); // song2が音声ファイル
  13. :
  14. playerTwo.start(); // 再生
  15. :
  16. playerTwo.stop(); // 停止
  17. try{
  18. playerTwo.prepare(); // 再生準備
  19. }
  20. catch (IOException e){
  21. e.printStackTrace();
  22. }
  23. :
  24. playerTwo.seekTo(0); // そして、再生位置を先頭に…しようとするとエラー!
  25. // この行をコメントアウトすると、途中から再生できる
  26. playerTwo.start(); // 2回めの再生はエラーのため無視
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement