本文整理汇总了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());
}
}