设为首页 加入收藏

TOP

播放音乐案例(二)
2017-10-13 10:36:47 】 浏览:4916
Tags:播放 音乐 案例
ame="1.0" > 5 6 <uses-sdk 7 android:minSdkVersion="8" 8 android:targetSdkVersion="19" /> 9 10 <application 11 android:allowBackup="true" 12 android:icon="@drawable/ic_launcher" 13 android:label="@string/app_name" 14 android:theme="@style/AppTheme" > 15 <activity 16 android:name="fry.MainActivity" 17 android:label="@string/app_name" > 18 <intent-filter> 19 <action android:name="android.intent.action.MAIN" /> 20 21 <category android:name="android.intent.category.LAUNCHER" /> 22 </intent-filter> 23 </activity> 24 <activity android:name="fry.Activity01" android:exported="true"></activity> 25 26 <service android:name="fry.myService"> 27 28 </service> 29 30 </application> 31 32 </manifest>

 

第三步,播放或者结束音乐

 1 package fry;
 2 
 3 import com.example.playMusic.R;
 4 
 5 import android.app.Activity;
 6 import android.content.Intent;
 7 import android.os.Bundle;
 8 import android.view.View;
 9 
10 public class Activity01 extends Activity{
11     @Override
12     protected void onCreate(Bundle savedInstanceState) {
13         // TODO Auto-generated method stub
14         super.onCreate(savedInstanceState);
15         setContentView(R.layout.activity01);
16     }
17     
18     public void onClick(View view){
19         Intent intent=new Intent();
20         intent.setClass(this, myService.class);
21         switch(view.getId()){
22         case R.id.btn_start://播放音乐,启动服务
23             startService(intent);
24             break;
25         case R.id.btn_stop://结束音乐,停止服务
26             stopService(intent);
27             break;
28         }
29     }
30 }

 

首页 上一页 1 2 下一页 尾页 2/2/2
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇Android Studio发布项目到jcenter.. 下一篇Android打开相机和打开相册

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目