资 源 简 介
Android 简单播放歌曲功能演示,播放本地音乐,非网络播放,可播放、暂停,运行效果如截图所示,在编写时,要注意以下代码:
int status = 1;//当前的状态,1没有声音播放 ,2 正在播放声音,3暂停
ImageButton start;//播放、暂停按钮
ImageButton stop;//停止按钮
ActivityReceiver activityReceiver;
int status = 1;//当前的状态,1没有声音播放 ,2 正在播放声音,3暂停
public void onCreate(Bundle savedInstanceState) {//重写的onCreate方法
super.onCreate(savedInstanceState);
setContentView(R.layout.main);//设置当前的用户界面
start = (ImageButton) this.findViewById(R.id.start);//得到start的引用
stop = (ImageButton) this.findViewById(R.id.stop);//得到stop按钮的引用
start.setOnClickListener(this);//为按钮添加监听
stop.setOnClickListener(this);//为按钮添加监听
activityReceiver = new ActivityReceiver();//创建BroadcastReceiver
IntentFilter filter = new IntentFilter();//创建IntentFilter过滤器
filter.addAction("wyf.ytl.update");//添加Action
registerReceiver(activityReceiver, filter);//注册监听
Intent intent = new Intent(this, MyService.class);//创建Intent
startService(intent);//启动后台Service
}