當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。