当前位置: 首页>>代码示例>>Java>>正文


Java MediaPlayer.setSurface方法代码示例

本文整理汇总了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();
        }
    }
 
开发者ID:Zhaoss,项目名称:WeiXinRecordedDemo,代码行数:25,代码来源:CutTimeActivity.java

示例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();
    }

}
 
开发者ID:WanAndroid,项目名称:LiveWallPaper,代码行数:22,代码来源:VideoLiveWallpaper.java

示例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("通知", "播放过程中出现了错误哦");
            }
        }
 
开发者ID:WanAndroid,项目名称:LiveWallPaper,代码行数:21,代码来源:CameraLiveWallpaper.java

示例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...
    }
}
 
开发者ID:nirhart,项目名称:shortrain,代码行数:20,代码来源:TutorialFragment.java

示例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();
    }
}
 
开发者ID:MirDong,项目名称:VideoWallPager,代码行数:18,代码来源:VideoLiveWallPaper.java

示例6: openVideo

import android.media.MediaPlayer; //导入方法依赖的package包/类
void openVideo(Surface surface) {
    if (mVideoResourceId == 0) {
        return;
    }
    mMediaPlayer = new MediaPlayer();
    mMediaPlayer.setSurface(surface);
    startVideo();
}
 
开发者ID:googlesamples,项目名称:android-PictureInPicture,代码行数:9,代码来源:MovieView.java

示例7: bindToMediaPlayer

import android.media.MediaPlayer; //导入方法依赖的package包/类
@TargetApi(16)
public void bindToMediaPlayer(MediaPlayer mp) {
    if (mp != null) {
        mp.setSurface(openSurface());
    }
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:7,代码来源:TextureRenderView.java


注:本文中的android.media.MediaPlayer.setSurface方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。