本文整理匯總了Java中android.media.MediaPlayer.setSurface方法的典型用法代碼示例。如果您正苦於以下問題:Java MediaPlayer.setSurface方法的具體用法?Java MediaPlayer.setSurface怎麽用?Java MediaPlayer.setSurface使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類android.media.MediaPlayer
的用法示例。
在下文中一共展示了MediaPlayer.setSurface方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: initMediaPlay
import android.media.MediaPlayer; //導入方法依賴的package包/類
private void initMediaPlay(SurfaceTexture surface){
try {
mMediaPlayer = new MediaPlayer();
mMediaPlayer.setDataSource(path);
mMediaPlayer.setSurface(new Surface(surface));
mMediaPlayer.setLooping(true);
mMediaPlayer.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
@Override
public void onPrepared(MediaPlayer mp) {
mMediaPlayer.start();
videoDuration = mMediaPlayer.getDuration();
videoWidth = mMediaPlayer.getVideoWidth();
videoHeight = mMediaPlayer.getVideoHeight();
initVideoSize();
initThumbs();
}
});
mMediaPlayer.prepareAsync();
}catch (Exception e){
e.printStackTrace();
}
}
示例2: onSurfaceCreated
import android.media.MediaPlayer; //導入方法依賴的package包/類
@Override
public void onSurfaceCreated(SurfaceHolder holder) {
L.d("VideoEngine#onSurfaceCreated ");
super.onSurfaceCreated(holder);
mMediaPlayer = new MediaPlayer();
mMediaPlayer.setSurface(holder.getSurface());
try {
AssetManager assetMg = getApplicationContext().getAssets();
AssetFileDescriptor fileDescriptor = assetMg.openFd("test1.mp4");
mMediaPlayer.setDataSource(fileDescriptor.getFileDescriptor(),
fileDescriptor.getStartOffset(), fileDescriptor.getLength());
mMediaPlayer.setLooping(true);
mMediaPlayer.setVolume(0, 0);
mMediaPlayer.prepare();
mMediaPlayer.start();
} catch (IOException e) {
e.printStackTrace();
}
}
示例3: play
import android.media.MediaPlayer; //導入方法依賴的package包/類
/**
* 播放
*/
private void play(SurfaceHolder surfaceHolder,String videoPath){
mediaPlayer = new MediaPlayer();
// 設置多媒體流類型
mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
// 設置用於展示mediaPlayer的容器
mediaPlayer.setSurface(surfaceHolder.getSurface());
// mediaPlayer.setDisplay(surfaceHolder);//用這個方法會報 Wallpapers do not support keep screen on
try {
mediaPlayer.setDataSource(videoPath);
mediaPlayer.prepare();
mediaPlayer.start();
mediaPlayer.setLooping(true);
} catch (Exception e) {
Log.i("通知", "播放過程中出現了錯誤哦");
}
}
示例4: onSurfaceTextureAvailable
import android.media.MediaPlayer; //導入方法依賴的package包/類
@Override
public void onSurfaceTextureAvailable(SurfaceTexture surface, int width, int height) {
Surface s = new Surface(surface);
int movieId = getArguments().getInt(MOVIE_RES_ID);
try {
mediaPlayer = new MediaPlayer();
String path = "android.resource://" + getContext().getPackageName() + "/" + movieId;
mediaPlayer.setDataSource(getContext(), Uri.parse(path));
mediaPlayer.setSurface(s);
mediaPlayer.prepare();
mediaPlayer.setLooping(true);
if (isVisible()) {
videoIsVisibleToUser();
}
} catch (Exception ignore) {
// This is an experiment...
}
}
示例5: onSurfaceCreated
import android.media.MediaPlayer; //導入方法依賴的package包/類
@Override
public void onSurfaceCreated(SurfaceHolder holder) {
super.onSurfaceCreated(holder);
mMediaPlayer = new MediaPlayer();
mMediaPlayer.setSurface(holder.getSurface());
try {
AssetManager assets = getApplicationContext().getAssets();
AssetFileDescriptor descriptor = assets.openFd("text1.mp4");
mMediaPlayer.setDataSource(descriptor.getFileDescriptor(),descriptor.getStartOffset(),descriptor.getLength());
mMediaPlayer.setLooping(true);
mMediaPlayer.setVolume(1.0f,1.0f);
mMediaPlayer.prepare();
mMediaPlayer.start();
} catch (IOException e) {
e.printStackTrace();
}
}
示例6: openVideo
import android.media.MediaPlayer; //導入方法依賴的package包/類
void openVideo(Surface surface) {
if (mVideoResourceId == 0) {
return;
}
mMediaPlayer = new MediaPlayer();
mMediaPlayer.setSurface(surface);
startVideo();
}
示例7: bindToMediaPlayer
import android.media.MediaPlayer; //導入方法依賴的package包/類
@TargetApi(16)
public void bindToMediaPlayer(MediaPlayer mp) {
if (mp != null) {
mp.setSurface(openSurface());
}
}