十年網(wǎng)站開發(fā)經(jīng)驗(yàn) + 多家企業(yè)客戶 + 靠譜的建站團(tuán)隊(duì)
量身定制 + 運(yùn)營維護(hù)+專業(yè)推廣+無憂售后,網(wǎng)站問題一站解決
生命周期:
公司主營業(yè)務(wù):做網(wǎng)站、網(wǎng)站設(shè)計(jì)、移動(dòng)網(wǎng)站開發(fā)等業(yè)務(wù)。幫助企業(yè)客戶真正實(shí)現(xiàn)互聯(lián)網(wǎng)宣傳,提高企業(yè)的競爭能力。成都創(chuàng)新互聯(lián)公司是一支青春激揚(yáng)、勤奮敬業(yè)、活力青春激揚(yáng)、勤奮敬業(yè)、活力澎湃、和諧高效的團(tuán)隊(duì)。公司秉承以“開放、自由、嚴(yán)謹(jǐn)、自律”為核心的企業(yè)文化,感謝他們對我們的高要求,感謝他們從不同領(lǐng)域給我們帶來的挑戰(zhàn),讓我們激情的團(tuán)隊(duì)有機(jī)會(huì)用頭腦與智慧不斷的給客戶帶來驚喜。成都創(chuàng)新互聯(lián)公司推出海城免費(fèi)做網(wǎng)站回饋大家。
注:播放完畢之后進(jìn)入PlaybackCompleted狀態(tài)。
播放視頻:
public void setDisplay (SurfaceHolder sh)
Since: API Level 1
設(shè)置用于視頻顯示的SurfaceHolder。不論是surface holder或是surface,如果視頻庫需要,就必須設(shè)置。當(dāng)播放一個(gè)視頻而沒有調(diào)用這個(gè)函數(shù)或是沒有調(diào)用setSurface(Surface),那么只會(huì)播放音頻了。一個(gè)空的surface holder或空的surface將會(huì)導(dǎo)致僅僅播放音頻。
android.view.Surface:Handle onto a raw buffer that is being managed by the screen compositor.
android.view.SurfaceView:Provides a dedicated drawing surface embedded inside of a view hierarchy. You can control the format of this surface and, if you like, its size; the SurfaceView takes care of placing the surface at the correct location on the screen.
SurfaceHolder是控制surface的一個(gè)抽象接口,你可以通過SurfaceHolder來控制surface的尺寸和格式,或者修改surface的像素,監(jiān)視surface的變化等等,SurfaceHolder是SurfaceView的典型接口。
SurfaceView和Surface的關(guān)系:Surface是管理顯示內(nèi)容的數(shù)據(jù)(implementsParcelable),包括存儲(chǔ)于數(shù)據(jù)的交換。而SurfaceView就是把這些數(shù)據(jù)顯示出來到屏幕上面。
SurfaceHolder.Callback是監(jiān)聽surface改變的一個(gè)接口。它的方法有:
public abstract void surfaceChanged(SurfaceHolder holder, int format, int width, int height) public abstract voidsurfaceCreated(SurfaceHolder holder) public abstract voidsurfaceDestroyed(SurfaceHolder holder)
代碼:
public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); mediaPlayer = new MediaPlayer(); nameText = (EditText) this.findViewById(R.id.filename); surfaceView = (SurfaceView) this.findViewById(R.id.surfaceView); //把輸送給surfaceView的視頻畫面,直接顯示到屏幕上,不要維持它自身的緩沖區(qū) surfaceView.getHolder().setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS); surfaceView.getHolder().setFixedSize(176, 144); surfaceView.getHolder().setKeepScreenOn(true); surfaceView.getHolder().addCallback(new SurfaceCallback()); } private final class SurfaceCallback implements Callback{ public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) { } public void surfaceCreated(SurfaceHolder holder) { if(position>0 && path!=null){ play(position); position = 0; } } public void surfaceDestroyed(SurfaceHolder holder) { if(mediaPlayer.isPlaying()){ position = mediaPlayer.getCurrentPosition(); mediaPlayer.stop(); } } }