无法在Android中创建媒体播放器

时间:2012-11-21 07:34:09

标签: android android-mediaplayer

我开发了一个简单的应用程序,一旦活动开始,警报将在一段时间内启动。我已经在模拟器中尝试过编码,但它确实有效。但是当我在手机中运行该应用程序(Android 2.3.5)时,应用程序会强行关闭。

RemoteAlarmActivity.java

MediaPlayer mp;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    mp = MediaPlayer.create(RemoteAlarmActivity.this, R.raw.music);
    Log.d(this.getClass().getName(), "Alarm Created");

    try {
        mp.prepare();
    } catch (IllegalStateException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    mp.start();
    Log.d(this.getClass().getName(), "Alarm Started");

    Handler h = new Handler();
    Runnable stopPlaybackRun = new Runnable() {
        public void run(){
            mp.stop();
            mp.release();
        }    
    };
    h.postDelayed(stopPlaybackRun, 20 * 1000);
}

logcat的

11-21 15:27:23.192: E/MediaPlayer(13047): Unable to to create media player
11-21 15:27:23.292: D/MediaPlayer(13047): create failed:
11-21 15:27:23.292: D/MediaPlayer(13047): java.io.IOException: setDataSourceFD failed.: status=0x80000000
11-21 15:27:23.292: D/MediaPlayer(13047):   at android.media.MediaPlayer.setDataSource(Native Method)
11-21 15:27:23.292: D/MediaPlayer(13047):   at android.media.MediaPlayer.create(MediaPlayer.java:704)
11-21 15:27:23.292: D/MediaPlayer(13047):   at com.testing.alarm.RemoteAlarmActivity.onCreate(RemoteAlarmActivity.java:21)
11-21 15:27:23.292: D/MediaPlayer(13047):   at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1072)
11-21 15:27:23.292: D/MediaPlayer(13047):   at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1836)
11-21 15:27:23.292: D/MediaPlayer(13047):   at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1893)
11-21 15:27:23.292: D/MediaPlayer(13047):   at android.app.ActivityThread.access$1500(ActivityThread.java:135)
11-21 15:27:23.292: D/MediaPlayer(13047):   at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1054)
11-21 15:27:23.292: D/MediaPlayer(13047):   at android.os.Handler.dispatchMessage(Handler.java:99)
11-21 15:27:23.292: D/MediaPlayer(13047):   at android.os.Looper.loop(Looper.java:150)
11-21 15:27:23.292: D/MediaPlayer(13047):   at android.app.ActivityThread.main(ActivityThread.java:4385)
11-21 15:27:23.292: D/MediaPlayer(13047):   at java.lang.reflect.Method.invokeNative(Native Method)
11-21 15:27:23.292: D/MediaPlayer(13047):   at java.lang.reflect.Method.invoke(Method.java:507)
11-21 15:27:23.292: D/MediaPlayer(13047):   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:849)
11-21 15:27:23.292: D/MediaPlayer(13047):   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:607)
11-21 15:27:23.292: D/MediaPlayer(13047):   at dalvik.system.NativeStart.main(Native Method)
11-21 15:27:23.302: D/com.testing.alarm.RemoteAlarmActivity(13047): Alarm Created

附件是编码的一部分以及logcat。有人可以帮我指出我的编码有什么问题吗?感谢...

0 个答案:

没有答案