2011.08.12——— android MediaPlayer

    2011.08.12——— android mediaplayer

写一个简单的播放mp3的程序,一直报错

debug/mediaplayer(3662): java.io.ioexception: prepare failed.: status=0x1


很是郁闷

后来感觉是
mmediaplayer.prepare();

必须单独try catch起来 当我爸try catch去掉时 一样报上面的错误

不是很明白

package com.lp;import java.io.ioexception;import android.app.activity;import android.media.mediaplayer;import android.os.bundle;import android.view.view;import android.view.view.onclicklistener;import android.widget.button;public class mainactivity extends activity {	private button play;	private button stop;	private boolean 	isreleased		= false;	private boolean 	isplaying		= false;	private mediaplayer mmediaplayer = new mediaplayer();    @override    public void oncreate(bundle savedinstancestate) {        super.oncreate(savedinstancestate);        setcontentview(r.layout.main);        play = (button)findviewbyid(r.id.main_play);        stop = (button)findviewbyid(r.id.main_stop);        play.setonclicklistener(new onclicklistener() {			@override			public void onclick(view v) {				try				{					if ( !isplaying )					{						/* 装载资源中的音乐 */						mmediaplayer = mediaplayer.create(mainactivity.this, r.raw.aa);						isplaying = true;						isreleased = false;						/* 设置是否循环 */						mmediaplayer.setlooping(true);						try						{							mmediaplayer.prepare();						}						catch (illegalstateexception e)						{							e.printstacktrace();						}						catch (ioexception e)						{							e.printstacktrace();						}												mmediaplayer.start();											}				}				catch (illegalstateexception e)				{					e.printstacktrace();				}			}        });                stop.setonclicklistener(new onclicklistener() {						@override			public void onclick(view v) {				if(isplaying&&!isreleased){					isreleased = true;					mmediaplayer.stop();					mmediaplayer.release();					isplaying = false;				}			}		});    }				}

 

你可能感兴趣的:(java,工作)