5、播放音頻隨身聽實驗參考_第1頁
5、播放音頻隨身聽實驗參考_第2頁
5、播放音頻隨身聽實驗參考_第3頁
5、播放音頻隨身聽實驗參考_第4頁
免費預(yù)覽已結(jié)束,剩余1頁可下載查看

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認領(lǐng)

文檔簡介

音頻【實驗內(nèi)容】音頻【實驗?zāi)康摹烤帲ê唽懸灰椎膫€u”)音頻e器。p“j,文n稱是m于:jg3音頻【實驗內(nèi)容】音頻【實驗?zāi)康摹烤帲ê唽懸灰椎膫€u”)音頻e器。p“j,文n稱是m于:jg3【實驗平臺】開Android4.0境。板,【關(guān)鍵代碼】源1源 Main.java:文件 :publicclassMainextendsActivity{privateImageButtonbtnPlay,btnPause,btnStop;privateTextViewtv;privateMediaPlayermp;publicvoidonCreate(BundlesavedInstanceState){super.onCreate(savedInstanceState);setContentView(R.layout.main);//通 findViewById找過 到資btnPlay=(ImageButton)findViewById(R.id.btnPlay);btnPause=(ImageButton)findViewById(R.id.btnPause);btnStop=(ImageButton)findViewById(R.id.btnStop);tv=(TextView)findViewById(R.id.txtStatus);//創(chuàng) MediaPlayer對,2中 象 方法//1://mp=MediaPlayer.create(this,R.raw.qingge);//2:mp=newMediaPlayer();try{mp.setDataSource("/mnt/sdcard/juejing.mp3");}catch(IllegalArgumentExceptione1){e1.printStackTrace();tv.setText("打開文件發(fā)生異常...");}catch(IllegalStateExceptione1){//2:mp=newMediaPlayer();try{mp.setDataSource("/mnt/sdcard/juejing.mp3");}catch(IllegalArgumentExceptione1){e1.printStackTrace();tv.setText("打開文件發(fā)生異常...");}catch(IllegalStateExceptione1){e1.printStackTrace();tv.setText("打開文件發(fā)生異常...");}catch(IOExceptione1){e1.printStackTrace();tv.setText("打開文件發(fā)生異常...");}//音樂按鈕的事件ImageButton.OnClickListener(){publicvoidonClick(Viewv){try{if(!mp.isPlaying()){mp.prepare();mp.start();}}catch(Exceptione){中...");發(fā)生異常...");e.printStackTrace();}}});//暫停的事件btnPause.setOnClickListener(newImageButton.OnClickListener(){publicvoidonClick(Viewv){try{if(mp!=null&&mp.isPlaying()){mp.pause();!");}}catch(Exceptione){e.printStackTrace();2}}});//停止的事件btnStop.setOnClickListener(newImageButton.OnClickListener(){publicvoidonClick(Viewv){try{if(mp!=null}}});//停止的事件btnStop.setOnClickListener(newImageButton.OnClickListener(){publicvoidonClick(Viewv){try{if(mp!=null&&mp.isPlaying()){mp.stop();mp.reset();...");}}catch(Exceptione){e.printStackTrace();}}});/*當pletionLister會運行的Listener*/pletionListener(new//@OverridepletionListener(){/*覆蓋文件publicvoidtry{/**/pletion(MediaPlayerarg0){*MediaPlayer的賦值關(guān)系讓資源可以為其它程序利用*//*TextView為*/}catch(Exceptione){e.printStackTrace();}}});/*MediaPlayer.OnErrorListenerListener*/mp.setOnErrorListener(newMediaPlayer.OnErrorListener(){3【實驗現(xiàn)象】4/**/【實驗現(xiàn)象】4/**/publicbooleanonError(MediaPlayerarg0,intarg1,intarg2){try{/*MediaPlayer的賦值*/mp.release();tv.setText(" 發(fā)生異常!");}catch(Exceptione){e.printStackTrace();}returnfalse;}});}}源文件:main.xml:<?xmlversion="1.0"encoding="utf-8"?><LinearLayoutxmlns:android="http://s /apk/res/android"android:orientation="vertical"android:layout_width="fill_parent"android:layout_height="fill_parent"android:id="@+id/ll1"><TextViewandroid:text="TextView"android:id="@+id/txtStatus"<LinearLayoutandroid:layout_width="fill_parent"android:gravity="center_horizontal"android:orientation="horizontal"android:id="@+id/ll2">android:id="@+id/btnPlay"android:src="@drawable/play"android:layout_width="wrap_content"android:layout_height="wrap_content"></ImageButton><ImageButtonandroid:id="@+id/btnPause"android:src="@drawable/pause"android:layout_width="wrap_content"android:layout_height="wrap_content"></ImageButton><ImageButtonandroid:id="@+id/b

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責。
  • 6. 下載文件中如有侵權(quán)或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論