Android声音媒体播放器IllegalStateException且没有声音

时间:2016-06-02 06:24:28

标签: java android

  

java.lang.RuntimeException:无法恢复活动MainActivity}:   java.lang.IllegalStateException引起:   java.lang.IllegalStateException                                                                                                在android.media.MediaPlayer.prepare(本机方法)                                                                                                在   com.example.caneraydin.androidwithlogin.MainActivity.onResume(MainActivity.java:138)

对于此代码

@Override
    public void onResume() {
        super.onResume();
        MediaPlayer mMediaPlayer = new MediaPlayer();
        mMediaPlayer = MediaPlayer.create(this,R.raw.mainactivitymp3);
        mMediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
        mMediaPlayer.setLooping(true);
        try {
          mMediaPlayer.prepare();
          Log.d(TAG,"mainonresumemediaplayer");
        } catch (IOException e) {
          Log.d(TAG,"mainonresume mediaplayer error");
            e.printStackTrace();
        }
        mMediaPlayer.start();//.release();// STOPSHIP: 6/2/2016

我只有这里,而不是其他东西。 所以我将所有代码移动到onCreate,但

仍然是相同的错误
prepare

线。

当我删除准备时,

  MediaPlayer mMediaPlayer = new MediaPlayer();
    mMediaPlayer = MediaPlayer.create(this, R.raw.mainactivitymp3);
    mMediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
    mMediaPlayer.setLooping(true);
    mMediaPlayer.start();//.release();// STOPSHIP: 6/2/2016

没有声音。它写的时候我才开始主动活动(主要活动永远保持活跃,直到点击嗅觉)

  

E / MediaPlayer:应该已经设置了字幕控制器

     

MediaPlayer最终确定没有被释放(我没有完成   主动,仍然活跃)

.493 760-769/? V/MediaPlayer-JNI: native_finalize
.493 760-769/? V/MediaPlayer-JNI: release
.543 760-769/? V/MediaPlayer-JNI: native_finalize
.543 760-769/? V/MediaPlayer-JNI: release
.543 24067-24067/com.example W/ApplicationPackageManager: getCSCPackageItemText()
.543 760-769/? V/MediaPlayer-JNI: native_finalize
.543 760-769/? V/MediaPlayer-JNI: release
.733 24067-24067/com.example V/MediaPlayer-JNI: native_setup
.733 24067-24067/com.example V/MediaPlayer: constructor
.743 24067-24067/com.example V/MediaPlayer: setListener
.753 24067-24067/com.example V/MediaPlayer-JNI: native_setup
.753 24067-24067/com.example V/MediaPlayer: constructor
.753 24067-24067/com.example V/MediaPlayer: setListener
.753 24067-24067/com.example V/MediaPlayer-JNI: setDataSourceFD: fd 49
.753 24067-24067/com.example V/MediaPlayer: setDataSource(49, 597544, 1376079)
.763 168-556/? V/MediaPlayerService: Create new client(312) from pid 24067, uid 10177, 
.763 168-430/? V/MediaPlayerService: setDataSource fd=39, offset=597544, length=1376079
.763 168-430/? V/MediaPlayerService: st_dev  = 45849
.763 168-430/? V/MediaPlayerService: st_mode = 33188
.763 168-430/? V/MediaPlayerService: st_uid  = 1000
.763 168-430/? V/MediaPlayerService: st_gid  = 1000
.763 168-430/? V/MediaPlayerService: st_size = 3186530
.763 168-430/? V/MediaPlayerService: player type = 3
.773 168-430/? V/AudioSink: AudioOutput(1947)
.773 168-430/? V/MediaPlayerService: [312] notify (0xb7d93b78, 8, 0, 0)
.773 24067-24079/com.example V/MediaPlayer: message received msg=8, ext1=0, ext2=0
.773 24067-24079/com.example V/MediaPlayer: notify(8, 0, 0) callback on disconnected mediaplayer
.833 167-19415/? D/WVMDrmPlugIn: WVMDrmPlugin::onInitialize : 6449
.833 167-19415/? D/WVMDrmPlugIn: WVMDrmPlugin::onSetOnInfoListener : add 6449
.843 167-167/? D/WVMDrmPlugIn: WVMDrmPlugin::onTerminate : 6449
.843 168-430/? V/MediaExtractor: Autodetected media content as 'audio/mpeg' with confidence 0.20
.843 168-30639/? V/MediaPlayerService: [312] getParameter(1700)
.843 24067-24067/com.example V/MediaPlayer: setVideoSurfaceTexture
.843 168-868/? V/MediaPlayerService: [312] setVideoSurfaceTexture(0x0)
.843 24067-24067/com.example V/MediaPlayer: prepare
.843 168-168/? V/MediaPlayerService: [312] setAudioStreamType(3)
.843 168-20316/? V/MediaPlayerService: [312] prepareAsync
.873 168-24099/? V/MediaPlayerService: [312] notify (0xb7d93b78, 5, 0, 0)
.873 168-24099/? V/MediaPlayerService: [312] notify (0xb7d93b78, 1, 0, 0)
.873 24067-24078/com.example V/MediaPlayer: message received msg=5, ext1=0, ext2=0
.873 24067-24078/com.example V/MediaPlayer: New video size 0 x 0
.873 24067-24078/com.example V/MediaPlayer: callback application
.873 24067-24078/com.example V/MediaPlayer: back from callback
.873 24067-24078/com.example V/MediaPlayer: message received msg=1, ext1=0, ext2=0
.873 24067-24078/com.example V/MediaPlayer: prepared
.873 24067-24078/com.example V/MediaPlayer: signal application thread
.873 24067-24078/com.example V/MediaPlayer: callback application
.873 24067-24067/com.example V/MediaPlayer: prepare complete - status=0
.873 24067-24067/com.example V/MediaPlayer-JNI: setAudioStreamType: 3
.873 24067-24078/com.example V/MediaPlayer: back from callback
.873 24067-24067/com.example V/MediaPlayer: MediaPlayer::setAudioStreamType
.873 24067-24067/com.example V/MediaPlayer-JNI: setLooping: 1
.873 24067-24067/com.example V/MediaPlayer: MediaPlayer::setLooping
.873 168-556/? V/MediaPlayerService: [312] setLooping(1)
.873 24067-24067/com.example V/MediaPlayer-JNI: start
.873 24067-24067/com.example V/MediaPlayer: start
.873 168-430/? V/MediaPlayerService: [312] setLooping(1)
.873 168-30639/? V/MediaPlayerService: [312] setVolume(1.000000, 1.000000)
.873 168-30639/? V/AudioSink: setVolume(1.000000, 1.000000)
.873 168-30639/? V/MediaPlayerService: [312] setAuxEffectSendLevel(0.000000)
.873 168-30639/? V/AudioSink: setAuxEffectSendLevel(0.000000)
.873 168-168/? V/MediaPlayerService: [312] start
.883 168-168/? V/MediaPlayerService: [312] notify (0xb7d93b78, 6, 0, 0)
.883 24067-24079/com.example V/MediaPlayer: message received msg=6, ext1=0, ext2=0
.883 24067-24067/com.example D/Chic: MAINACTIVITY OnCreate*************
.883 24067-24079/com.example V/MediaPlayer: Received MEDIA_STARTED
.883 24067-24079/com.example V/MediaPlayer: callback application
.883 24067-24079/com.example V/MediaPlayer: back from callback
06-02 09:25:27.324 24067-24067/com.example I/MediaPlayer: Don't send intent. msg.arg1 = 0, msg.arg2 = 0
06-02 09:25:27.324 24067-24067/com.example E/MediaPlayer: Should have subtitle controller already set
06-02 09:25:27.424 24067-24067/com.example D/OpenGLRenderer: Enabling debug mode 0
06-02 09:25:27.494 24067-24067/com.example V/MediaPlayer-JNI: getCurrentPosition: 720 (msec)
06-02 09:25:27.494 24067-24067/com.example V/MediaPlayer-JNI: isPlaying: 1
06-02 09:25:27.534 24067-24146/com.example I/dalvikvm-heap: Grow heap (frag case) to 13.910MB for 3112976-byte allocation
06-02 09:25:27.624 24067-24076/com.example V/MediaPlayer-JNI: native_finalize
06-02 09:25:27.624 24067-24146/com.example D/dalvikvm: GC_FOR_ALLOC freed 3480K, 32% free 9389K/13768K, paused 25ms, total 35ms
06-02 09:25:27.624 24067-24076/com.example W/MediaPlayer-JNI: MediaPlayer finalized without being released
06-02 09:25:27.624 24067-24076/com.example V/MediaPlayer-JNI: release
06-02 09:25:27.624 24067-24076/com.example V/MediaPlayer: setListener
06-02 09:25:27.624 24067-24076/com.example V/MediaPlayer: disconnect
06-02 09:25:27.624 24067-24076/com.example V/MediaPlayer: destructor
06-02 09:25:27.624 24067-24076/com.example V/MediaPlayer: disconnect
06-02 09:25:27.624 24067-24076/com.example V/MediaPlayer-JNI: native_finalize
06-02 09:25:27.624 24067-24076/com.example W/MediaPlayer-JNI: MediaPlayer finalized without being released
06-02 09:25:27.624 24067-24076/com.example V/MediaPlayer-JNI: release
06-02 09:25:27.624 24067-24076/com.example V/MediaPlayer: setListener
06-02 09:25:27.624 24067-24076/com.example V/MediaPlayer: disconnect
06-02 09:25:27.624 168-430/? V/MediaPlayerService: disconnect(312) from pid 24067
06-02 09:25:27.644 168-430/? I/AudioPlayer: reset out
06-02 09:25:27.644 168-430/? I/SecMediaClock: SecMediaClock destructor
06-02 09:25:27.644 24067-24076/com.example V/MediaPlayer: destructor
06-02 09:25:27.644 24067-24076/com.example V/MediaPlayer: disconnect
06-02 09:25:27.644 168-30639/? V/MediaPlayerService: Client(312) destructor pid = 24067
06-02 09:25:27.644 168-30639/? V/AudioSink: +++ close
06-02 09:25:27.644 168-30639/? V/AudioSink: --- close
06-02 09:25:27.644 168-30639/? V/MediaPlayerService: disconnect(312) from pid 24067

我没有添加任何权限。我现在的那些:

   <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"></uses-permission>
    <uses-permission android:name="android.permission.READ_PHONE_STATE"></uses-permission>
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

Android rebuild project, package org.junit does not exist error

这可能是理由吗?

我只能听到0.5秒。我重复了很多次,只有一次我可以在这里。

1 个答案:

答案 0 :(得分:0)

试试这个: -

    try{
       MediaPlayer mediaPlayer = MediaPlayer.create(this, R.raw.kalimba);
       mediaPlayer.start();          
    }  catch(Exception e) {
        e.printStackTrace();
    }