您好,登錄后才能下訂單哦!
生命周期:
注:播放完畢之后進入PlaybackCompleted狀態。
播放視頻:
public void setDisplay (SurfaceHolder sh)
Since: API Level 1
設置用于視頻顯示的SurfaceHolder。不論是surface holder或是surface,如果視頻庫需要,就必須設置。當播放一個視頻而沒有調用這個函數或是沒有調用setSurface(Surface),那么只會播放音頻了。一個空的surface holder或空的surface將會導致僅僅播放音頻。
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的一個抽象接口,你可以通過SurfaceHolder來控制surface的尺寸和格式,或者修改surface的像素,監視surface的變化等等,SurfaceHolder是SurfaceView的典型接口。
SurfaceView和Surface的關系:Surface是管理顯示內容的數據(implementsParcelable),包括存儲于數據的交換。而SurfaceView就是把這些數據顯示出來到屏幕上面。
SurfaceHolder.Callback是監聽surface改變的一個接口。它的方法有:
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的視頻畫面,直接顯示到屏幕上,不要維持它自身的緩沖區 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(); } } }
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。