O

<?xml version»" 1. 0" encoding=Mutf-8"?>

<LinearLayout xm 1 ns: Android-"http: //schemas. Android.

com/apk/res/Android"

Android:orientation="vertical" Android:layout width "fill_parent"

Android:1ayout height="fill_parent" >

<TextView

Android:layoutjwidth "fill parent" Android:layout height-"wrap content" Android:text "@st_ring/hello" />

<Button

Android: id="@ ♦ id/stcirL" Android:layout_width "fill_parent" Android:layout height="wrap content" Android :text-"St.art Play" />

Craat* pr»j«cl fr™ nliliM iwn •J »«. ¿»t nU i IK«*;»

Opt* Srart. Pr«;««' kuiT»-.i Up>f> Ssvn Cm(1. UC

A|»U«*<>«>. MM JU|S«I»m ?v.k»*t k«m i«c» ifatkr^l H«j*iir»i<«

Eiaiifc C«n

A if] 10-9 frSt^g n 10 M -Service j&fflSCIJl

<But ton

Android:id="@+id/stop" Android:layout width^"fill_parent" Android:layout_height="wrap content" Android: t.ext = "Stop P ay" />

</L i n ea rLa you t> ftftlfffi jfc^SRffl LincarLayoufftiJ.^.*. ill "^ih" H+fetMlMH.

PlayService.java, 3?iJlHWi«l K:

package com.iceskysl.PlayService;

irnport Android.app.Activity; import Android.content.1ntent; import Android.os.Bundle; import Android.view.View;

import Android.vi.ew. View . OnCl ickListener ; import Android.widget.Button;

public class PlayService extends Activ. ty { /** Called when the activity is first created. */ COverride public void onCreate(Bundle savedlnstanceState) { super.onCreate(savedlnstanceState); setContentView(R.layout.main);

Button buttonl = (Button)findViewByld(R.id.start); button 1 . setOnCl rckl.i stener (startT t) ; Button button2 = (Button)findViewByld(R.id.stop); button?.setOnClickListener(stopit); )

private OnClickListener startlt = new OnClickListener() (

public void onClick(View v) {

startService(new Intent("com.iceskysl.PlayService.START AUDIO SERVICE")); ) } ;

private OnClickListener stoplt = new OnClickListener() (

public void onClick(View v) {

stopService(new Intent("com.iceskysl.PlayService. START AUDIO SERVICE"));

fiuiiii wftwmnmuvi ^s^m&^m^ii startService(new

Intent("com.iceskysl.PlayService. START AUDIO SERV[CE")) ;

1. f J

a m 10-10 Service

/ m i & & * 0 Andriod ft Servicc £, & ijP ff ¥ ft ft «5 *P'T 0T *:

package coin, iceskysl . PlayService;

import Android.app.Serv ice; import Android . content-. Intents-import Android.media.MediaPlayer; import Android.os.IBinder;

public claiss Music extends Service ( private MediaPlayer player;

(¿Override public IBinder onBind(tntent intent) { // T0D0 Auto-generated method stub return null; }

public void onStart(Intent intent, int startld) { super.onStart(intent, startld); player = MediaPlayer.create(this, R.raw.gequ); player.start();

public void onDestroyO i super.onDestroy(); player.stop();

ffiiiJ ir^l-llij "t" MediaPlayer player. «JG&Jt onStart + »/AffifeW MP3 Aft C&W, gequ.mP3), «teWfibk«»», iiUi/i: AndroidManifest.xml Ait+^JU*^^ Service ffaiMj, F0f>R:

<?xml version®" 1.0" encoding "ut.f-8"?>

<manifest xmlns:Android-"http://schemas.Android.com/apk/res/Android" package^"com.iceskysl.PlayService" Android:versionCode "1" Android:versionName-"1.0.0">

«application Android:icon="@drawable/icon" Android:label="@string/app name"> <activity Android:name=".PlayService"

Android: J abel-,,@$tring/app_name"> <intent-filter>

<action Android:name="Android.intent.action.MAIN" /> «category Android:name="Android.intent.category.LAUNCHER" /> </intent-f i 1 t.er> </activity>

<Service Android:name=".Music"> <intent-filter>

<action Android:name="com.iceskysl.PlayService.START AUDIO SERVICE" /> <category Android:name="Android.intent.category, default" /> </intent-filter> </Service>

I</application> </manifest>

njassj, ffiffji^tol 7 t-^if-^ "Music" A<J Service, it Action *J>V.>j

I "com.iceskysl.PlayService.START_AODXO_SEBVICE"

r.frr, fciW 10-11

ft M 10-11 4" "Start Ptay'Vs. &W M»til ft lill fft /f>"

n, sm^jKfti^ffi- "stoppiay" m ffikJStt, nttiBtb&ffl.

$ 1?: 4-: Vitm 7 Service KHR&fllttffl till. j' -f l«J B ¿)l /jjX F (ft Service * N £ iftMJ ffi,

«JfrttfflM^h« Service.

Service Ml^S^ Scrvice, iljH-m^M^EMitt

Android ÄfflWS*^

tilt Android fr_l

. iß ® «f» «s scfr s w if « ¿ föj & t « M m e ;

imrfriïmmw,. Äit«**®'. ñfcftn^Rœ±mw-M&m JLM, jwfiftf t^ifiirifôWiôÈW^^, nmnmmmjs, affstwra^sfflw«*^^®!. mrr¡m & mmr K-îêm ai it.

)rj¿«f-M^íEó^w.. i«îtt»«*mm. fciíMnmw i££:fctttt«1>lS. Bj*ASS«fîilïjS-fîÂf?., tornas. «5

'A&^m n i¿ m s & m » h & & m & ;>v: i h b #¡ m « & m #r ë ft.ïm n uu m n tt >:& œ

rtimiJVciß^/M/nw jiSffffi. JMÉW^KMjiMj -«3KWJS, t»íwfômmmlnl>r-

* rttMi XML 15® 7 i: flirrt-ff. Ä+t tmmifofrw imm

0 0

Post a comment