0

我遇到了这个问题,音频只是不想播放。没有错误,但是当我应该听到音乐时,我听不到音乐。这是下面的代码和logcat。我不知道如何阅读 logcat,这可能有助于解决问题。

public void start1(final View view)
    {
    setContentView(R.layout.timer); 
    if(path1.equals("default"))
     {
         path1="R.raw.iwilltouchthesky.mp3";
     }


     mp.reset();
     try {
        mp.setDataSource(path1);
    } catch (IllegalArgumentException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IllegalStateException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
     mp.start();    
    text = (TextView) this.findViewById(R.id.textView1);
    text2 = (TextView) this.findViewById(R.id.textView3);
    a=new CountDownTimer(interval1*1000, 1000) {
        public void onTick(long millisUntilFinished) {
            text.setText("Seconds Remaining: " + (millisUntilFinished / 1000));
            text2.setText("Repetitions Left: "+repsleft);
        }

        public void onFinish() {
            mp.stop();
         start2(view);
        }
     }.start();
    }

日志猫

01-26 20:28:48.620: I/InputReader(1908): dispatchTouch::touch event's action is 0 (deviceType=0) [pCnt=1, pending(waiting finished signal)=0]
01-26 20:28:48.620: I/InputDispatcher(1908): Delivering touch to current input target: action: 0, channel 'xxxx'
01-26 20:28:48.620: I/InputDispatcher(1908): Delivering touch to current input target: action: 0, channel 'xxxx'
01-26 20:28:48.620: D/LightsService(1908): setLight_native: 2
01-26 20:28:48.620: E/lights(1908): write_int: path /sys/devices/virtual/sec/sec_touchkey/brightness, value 1
01-26 20:28:48.620: I/PowerManagerService(1908): Ulight 3->7|0
01-26 20:28:48.620: D/PowerManagerService(1908): setLightBrightness : mButtonLight : 118
01-26 20:28:48.620: V/LightsService(1908): setLight #2 #ff767676
01-26 20:28:48.695: I/InputReader(1908): dispatchTouch::touch event's action is 1 (deviceType=0) [pCnt=1, pending(waiting finished signal)=0]
01-26 20:28:48.695: I/InputDispatcher(1908): Delivering touch to current input target: action: 1, channel 'xxxx'
01-26 20:28:48.695: I/InputDispatcher(1908): Delivering touch to current input target: action: 1, channel 'xxxx'
01-26 20:28:48.695: I/AudioService(1908): playSoundEffect() type:0 volume:-1
01-26 20:28:48.700: I/AudioPolicyManagerBase(1757): getSituationVolume: isBTConnected:0 isHeadConnected:0
01-26 20:28:48.700: I/AudioPolicyManager(1757): getParamFromPolicy  deviceInt = 0, situationInt = 1, situationVolume = 0.300000
01-26 20:28:48.700: I/AudioPolicyManager(1757): startOutput() output 1, stream 1, session 17216
01-26 20:28:48.700: I/AudioFlinger(1757): start output streamType (0, 1) for 1
01-26 20:28:48.700: V/yamaha::media::VolumeCtrl(1757): VolumeCtrl::createVolume()
01-26 20:28:48.700: V/yamaha::media::UserDep(1757): UserDep::getRouteInfo(output: audioengine=0, devices=00000002h
01-26 20:28:48.700: V/yamaha::media::UserDep(1757):                       incall: onoff=0, devices=00000000h
01-26 20:28:48.700: V/yamaha::media::UserDep(1757):                       capture: onoff=0, devices=00100000h, audioSource=6
01-26 20:28:48.700: V/yamaha::media::UserDep(1757):                       playback: audio_onoff=0, line_onoff=0)
01-26 20:28:48.700: V/yamaha::media::UserDep(1757): ALL Off
01-26 20:28:48.700: V/yamaha::media::VolumeCtrl(1757): VolumeCtrl::setVolume()
01-26 20:28:48.700: D/yamaha::media::VolumeCtrl(1757): VolumeCtrl::setVolume() FM Playback: Ready
01-26 20:28:48.700: D/yamaha::media::VolumeCtrl(1757): VolumeCtrl::setVolume() VoiceCall: Ready
01-26 20:28:48.745: V/yamaha::media::VolumeCtrl(1757): VolumeCtrl::createVolume()
01-26 20:28:48.745: D/yamaha::media::VolumeCtrl(1757): Dir0      : AP Playback Music SP (0001h)
01-26 20:28:48.745: D/yamaha::media::VolumeCtrl(1757): Dir0Att   : AP Playback Music SP (0001h)
01-26 20:28:48.745: D/yamaha::media::VolumeCtrl(1757): DacMaster : AP Playback Music SP (0101h)
01-26 20:28:48.745: D/yamaha::media::VolumeCtrl(1757): Sp        : AP Playback Music SP (0001h)
01-26 20:28:48.745: E/yamaha::media::VolumeCtrl(1757): Dir0      : AP Playback Music SP (0001h)
01-26 20:28:48.745: E/yamaha::media::VolumeCtrl(1757): Dir0Att   : AP Playback Music SP (0001h)
01-26 20:28:48.745: E/yamaha::media::VolumeCtrl(1757): DacMaster : AP Playback Music SP (0101h)
01-26 20:28:48.745: E/yamaha::media::VolumeCtrl(1757): Sp        : AP Playback Music SP (0001h)
01-26 20:28:48.745: V/yamaha::media::UserDep(1757): UserDep::getRouteInfo(output: audioengine=0, devices=00000002h
01-26 20:28:48.745: V/yamaha::media::UserDep(1757):                       incall: onoff=0, devices=00000000h
01-26 20:28:48.745: V/yamaha::media::UserDep(1757):                       capture: onoff=0, devices=00100000h, audioSource=6
01-26 20:28:48.745: V/yamaha::media::UserDep(1757):                       playback: audio_onoff=1, line_onoff=0)
01-26 20:28:48.745: V/yamaha::media::UserDep(1757): Playback[Audio], Output[dev:DAC, NonAE]
01-26 20:28:48.745: V/yamaha::media::UserDep(1757): editDacDst(devices=2h) HPOUT Off
01-26 20:28:48.745: V/yamaha::media::UserDep(1757): editDacDst(devices=2h) RCOUT Off
01-26 20:28:48.745: V/yamaha::media::UserDep(1757): editDacDst(devices=2h) LINEOUT1 Off
01-26 20:28:48.745: V/yamaha::media::VolumeCtrl(1757): VolumeCtrl::setVolume()
01-26 20:28:48.745: D/yamaha::media::VolumeCtrl(1757): VolumeCtrl::setVolume() FM Playback: Ready
01-26 20:28:48.745: D/yamaha::media::VolumeCtrl(1757): VolumeCtrl::setVolume() VoiceCall: Ready
01-26 20:28:48.770: D/AndroidRuntime(16000): Shutting down VM
01-26 20:28:48.775: W/dalvikvm(16000): threadid=1: thread exiting with uncaught exception (group=0x40c251f8)
01-26 20:28:48.795: E/AndroidRuntime(16000): FATAL EXCEPTION: main
01-26 20:28:48.795: E/AndroidRuntime(16000): java.lang.IllegalStateException: Could not execute method of the activity
01-26 20:28:48.795: E/AndroidRuntime(16000):    at android.view.View$1.onClick(View.java:3098)
01-26 20:28:48.795: E/AndroidRuntime(16000):    at android.view.View.performClick(View.java:3620)
01-26 20:28:48.795: E/AndroidRuntime(16000):    at android.view.View$PerformClick.run(View.java:14292)
01-26 20:28:48.795: E/AndroidRuntime(16000):    at android.os.Handler.handleCallback(Handler.java:605)
01-26 20:28:48.795: E/AndroidRuntime(16000):    at android.os.Handler.dispatchMessage(Handler.java:92)
01-26 20:28:48.795: E/AndroidRuntime(16000):    at android.os.Looper.loop(Looper.java:137)
01-26 20:28:48.795: E/AndroidRuntime(16000):    at android.app.ActivityThread.main(ActivityThread.java:4507)
01-26 20:28:48.795: E/AndroidRuntime(16000):    at java.lang.reflect.Method.invokeNative(Native Method)
01-26 20:28:48.795: E/AndroidRuntime(16000):    at java.lang.reflect.Method.invoke(Method.java:511)
01-26 20:28:48.795: E/AndroidRuntime(16000):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:790)
01-26 20:28:48.795: E/AndroidRuntime(16000):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:557)
01-26 20:28:48.795: E/AndroidRuntime(16000):    at dalvik.system.NativeStart.main(Native Method)
01-26 20:28:48.795: E/AndroidRuntime(16000): Caused by: java.lang.reflect.InvocationTargetException
01-26 20:28:48.795: E/AndroidRuntime(16000):    at java.lang.reflect.Method.invokeNative(Native Method)
01-26 20:28:48.795: E/AndroidRuntime(16000):    at java.lang.reflect.Method.invoke(Method.java:511)
01-26 20:28:48.795: E/AndroidRuntime(16000):    at android.view.View$1.onClick(View.java:3093)
01-26 20:28:48.795: E/AndroidRuntime(16000):    ... 11 more
01-26 20:28:48.795: E/AndroidRuntime(16000): Caused by: java.lang.IllegalStateException
01-26 20:28:48.795: E/AndroidRuntime(16000):    at android.media.MediaPlayer._reset(Native Method)
01-26 20:28:48.795: E/AndroidRuntime(16000):    at android.media.MediaPlayer.reset(MediaPlayer.java:1339)
01-26 20:28:48.795: E/AndroidRuntime(16000):    at phil.H.com.HIITActivity.start1(HIITActivity.java:165)
01-26 20:28:48.795: E/AndroidRuntime(16000):    ... 14 more
01-26 20:28:48.835: I/ALSAModule(1757): Initialized ALSA PLAYBACK device hifi
01-26 20:28:48.860: E/android.os.Debug(1908): !@Dumpstate > dumpstate -k -t -n -z -d -o /data/log/dumpstate_app_error
01-26 20:28:48.870: I/dumpstate(16023): Check if stand-alone
01-26 20:28:48.875: D/dalvikvm(16000): GC_CONCURRENT freed 381K, 5% free 8972K/9415K, paused 4ms+2ms
01-26 20:28:48.885: I/dumpstate(16023): begin
01-26 20:28:49.000: I/AudioPolicyManager(1757): stopOutput() output 1, stream 1, session 17216
01-26 20:28:49.025: I/AudioFlinger(1757): stop output streamType (0, 1) for 1
01-26 20:28:49.360: W/ActivityManager(1908): Activity pause timeout for r
01-26 20:28:49.530: V/yamaha::media::VolumeCtrl(1757): VolumeCtrl::createVolume()
01-26 20:28:49.530: D/yamaha::media::VolumeCtrl(1757): Dir0      : AP Playback Music SP (0001h)
01-26 20:28:49.530: D/yamaha::media::VolumeCtrl(1757): Dir0Att   : AP Playback Music SP (0001h)
01-26 20:28:49.530: D/yamaha::media::VolumeCtrl(1757): DacMaster : AP Playback Music SP (0101h)
01-26 20:28:49.530: D/yamaha::media::VolumeCtrl(1757): Sp        : AP Playback Music SP (0001h)
01-26 20:28:49.530: E/yamaha::media::VolumeCtrl(1757): Dir0      : AP Playback Music SP (0001h)
01-26 20:28:49.530: E/yamaha::media::VolumeCtrl(1757): Dir0Att   : AP Playback Music SP (0001h)
01-26 20:28:49.530: E/yamaha::media::VolumeCtrl(1757): DacMaster : AP Playback Music SP (0101h)
01-26 20:28:49.530: E/yamaha::media::VolumeCtrl(1757): Sp        : AP Playback Music SP (0001h)
01-26 20:28:49.530: V/yamaha::media::UserDep(1757): UserDep::getRouteInfo(output: audioengine=0, devices=00000002h
01-26 20:28:49.530: V/yamaha::media::UserDep(1757):                       incall: onoff=0, devices=00000000h
01-26 20:28:49.530: V/yamaha::media::UserDep(1757):                       capture: onoff=0, devices=00100000h, audioSource=6
01-26 20:28:49.530: V/yamaha::media::UserDep(1757):                       playback: audio_onoff=1, line_onoff=0)
01-26 20:28:49.530: V/yamaha::media::UserDep(1757): Playback[Audio], Output[dev:DAC, NonAE]
01-26 20:28:49.530: V/yamaha::media::UserDep(1757): editDacDst(devices=2h) HPOUT Off
01-26 20:28:49.530: V/yamaha::media::UserDep(1757): editDacDst(devices=2h) RCOUT Off
01-26 20:28:49.530: V/yamaha::media::UserDep(1757): editDacDst(devices=2h) LINEOUT1 Off
01-26 20:28:49.530: V/yamaha::media::VolumeCtrl(1757): VolumeCtrl::setVolume()
01-26 20:28:49.530: D/yamaha::media::VolumeCtrl(1757): VolumeCtrl::setVolume() FM Playback: Ready
01-26 20:28:49.530: D/yamaha::media::VolumeCtrl(1757): VolumeCtrl::setVolume() VoiceCall: Ready
01-26 20:28:50.120: D/LightsService(1908): setLight_native: 2
01-26 20:28:50.120: E/lights(1908): write_int: path /sys/devices/virtual/sec/sec_touchkey/brightness, value 2
01-26 20:28:50.120: W/PowerManagerService(1908): Timer 0x7->0x3|0x0
01-26 20:28:50.120: I/PowerManagerService(1908): Ulight 7->3|0
01-26 20:28:50.120: D/PowerManagerService(1908): setLightBrightness : mButtonLight : 0
01-26 20:28:50.120: V/LightsService(1908): setLight #2 #ff000000
01-26 20:28:52.090: I/ALSAModule(1757): Terminated ALSA PLAYBACK device hifi
01-26 20:28:52.510: V/yamaha::media::VolumeCtrl(1757): VolumeCtrl::createVolume()
01-26 20:28:52.510: V/yamaha::media::UserDep(1757): UserDep::getRouteInfo(output: audioengine=0, devices=00000002h
01-26 20:28:52.510: V/yamaha::media::UserDep(1757):                       incall: onoff=0, devices=00000000h
01-26 20:28:52.510: V/yamaha::media::UserDep(1757):                       capture: onoff=0, devices=00100000h, audioSource=6
01-26 20:28:52.510: V/yamaha::media::UserDep(1757):                       playback: audio_onoff=0, line_onoff=0)
01-26 20:28:52.510: V/yamaha::media::UserDep(1757): ALL Off
01-26 20:28:52.510: V/yamaha::media::VolumeCtrl(1757): VolumeCtrl::setVolume()
01-26 20:28:52.510: D/yamaha::media::VolumeCtrl(1757): VolumeCtrl::setVolume() FM Playback: Ready
01-26 20:28:52.510: D/yamaha::media::VolumeCtrl(1757): VolumeCtrl::setVolume() VoiceCall: Ready
01-26 20:28:52.570: D/PowerManagerService(1908): mIsLockZone =  false
01-26 20:28:55.685: D/VoldCmdListener(1746): asec list
01-26 20:28:55.690: D/VoldCmdListener(1746): CommandListener::AsecCmd::runCommand -> -- 
01-26 20:28:56.095: D/BatteryService(1908): update start
01-26 20:28:56.095: D/BatteryService(1908): level:73 scale:100 status:2 health:2 present:true voltage: 4011 temperature: 310 technology: Li-ion AC powered:false USB powered:true icon:17302822 invalid charger:0
: E/(): Device disconnected
4

1 回答 1

0

试试这个 :

编辑:

//Play music
    public void playSound(int id){
            try{
                mp = MediaPlayer.create(mContext, id);
                mp.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
                    @Override
                    public void onPrepared(MediaPlayer arg0) {
                        mp.start();  
                    }
                });
                mp.setOnCompletionListener(new MediaPlayer.OnCompletionListener () {

                    @Override
                    public void onCompletion(MediaPlayer mp) {
                        // TODO Auto-generated method stub
                        mp.release();
                    }});
            }
            catch (Exception e) {
                // TODO: handle exception
                Log.v("Sound Exception","Sound Exception = "+e.getMessage());
            }
    }

并以这种方式调用,

playSound(R.raw.iwilltouchthesky);

您不能以这种方式"R.raw.iwilltouchthesky.mp3"raw文件夹中使用路径。

谢谢。

于 2013-01-27T04:13:43.897 回答