gpt4 book ai didi

java中初始化MediaRecorder的实现方法

转载 作者:qq735679552 更新时间:2022-09-28 22:32:09 25 4
gpt4 key购买 nike

CFSDN坚持开源创造价值,我们致力于搭建一个资源共享平台,让每一个IT人在这里找到属于你的精彩世界.

这篇CFSDN的博客文章java中初始化MediaRecorder的实现方法由作者收集整理,如果你对这篇文章有兴趣,记得点赞哟.

java中初始化MediaRecorder 。

实现代码:

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
private boolean initializeVideo() { 
     Log.v(TAG, "initializeVideo" ); 
     
     if (mSurfaceHolder == null ) { 
       Log.v(TAG, "SurfaceHolder is null" ); 
       return false
    
 
     mMediaRecorderRecording = true
 
     if (mMediaRecorder == null
         mMediaRecorder = new MediaRecorder(); 
     else
         mMediaRecorder.reset(); 
     if (mCamera != null ) { 
         if (Integer.parseInt(Build.VERSION.SDK) >= 8
             VideoCameraNew2.reconnect(mCamera); 
         mCamera.release(); 
         mCamera = null
    
 
     if (useFront && Integer.parseInt(Build.VERSION.SDK) >= 5 ) { 
             if (isAvailableSprintFFC) 
            
                 try
                
                     Method method = Class.forName( "android.hardware.HtcFrontFacingCamera" ).getDeclaredMethod( "getCamera" , null ); 
                     mCamera = (Camera) method.invoke( null , null ); 
                
                 catch (Exception ex) 
                
                     Log.d(TAG, ex.toString()); 
                
             } else
                 mCamera = Camera.open(); 
                 Camera.Parameters parameters = mCamera.getParameters(); 
                 parameters.set( "camera-id" , 2 ); 
                 mCamera.setParameters(parameters); 
            
             VideoCameraNew.unlock(mCamera); 
             mMediaRecorder.setCamera(mCamera); 
         mVideoPreview.setOnClickListener( this ); 
    
     mVideoPreview.setOnLongClickListener( this ); 
     mMediaRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA); 
     mMediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP); 
     mMediaRecorder.setOutputFile(sender.getFileDescriptor()); 
 
         mMediaRecorder.setVideoFrameRate( 20 ); 
     if (videoQualityHigh) { 
       mMediaRecorder.setVideoSize( 352 , 288 ); 
     } else
       mMediaRecorder.setVideoSize( 176 , 144 ); 
    
     mMediaRecorder.setVideoEncoder(MediaRecorder.VideoEncoder.H263); 
     mMediaRecorder.setPreviewDisplay(mSurfaceHolder.getSurface()); 
 
     try
       mMediaRecorder.prepare(); 
       mMediaRecorder.setOnErrorListener( this ); 
       mMediaRecorder.start(); 
     } catch (IOException exception) { 
       releaseMediaRecorder(); 
       finish(); 
       return false
    
     return true
   }
?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
private boolean initializeVideo() {
     Log.v(TAG, "initializeVideo" );
     
     if (mSurfaceHolder == null ) {
       Log.v(TAG, "SurfaceHolder is null" );
       return false ;
     }
 
     mMediaRecorderRecording = true ;
 
     if (mMediaRecorder == null )
         mMediaRecorder = new MediaRecorder();
     else
         mMediaRecorder.reset();
     if (mCamera != null ) {
         if (Integer.parseInt(Build.VERSION.SDK) >= 8 )
             VideoCameraNew2.reconnect(mCamera);
         mCamera.release();
         mCamera = null ;
     }
 
     if (useFront && Integer.parseInt(Build.VERSION.SDK) >= 5 ) {
             if (isAvailableSprintFFC)
             {
                 try
                 {
                     Method method = Class.forName( "android.hardware.HtcFrontFacingCamera" ).getDeclaredMethod( "getCamera" , null );
                     mCamera = (Camera) method.invoke( null , null );
                 }
                 catch (Exception ex)
                 {
                     Log.d(TAG, ex.toString());
                 }
             } else {
                 mCamera = Camera.open(); 
                 Camera.Parameters parameters = mCamera.getParameters(); 
                 parameters.set( "camera-id" , 2 ); 
                 mCamera.setParameters(parameters); 
             }
             VideoCameraNew.unlock(mCamera);
             mMediaRecorder.setCamera(mCamera);
         mVideoPreview.setOnClickListener( this );
     }
     mVideoPreview.setOnLongClickListener( this );
     mMediaRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
     mMediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
     mMediaRecorder.setOutputFile(sender.getFileDescriptor());
 
         mMediaRecorder.setVideoFrameRate( 20 );
     if (videoQualityHigh) {
       mMediaRecorder.setVideoSize( 352 , 288 );
     } else {
       mMediaRecorder.setVideoSize( 176 , 144 );
     }
     mMediaRecorder.setVideoEncoder(MediaRecorder.VideoEncoder.H263);
     mMediaRecorder.setPreviewDisplay(mSurfaceHolder.getSurface());
 
     try {
       mMediaRecorder.prepare();
       mMediaRecorder.setOnErrorListener( this );
       mMediaRecorder.start();
     } catch (IOException exception) {
       releaseMediaRecorder();
       finish();
       return false ;
     }
     return true ;
   }
?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
private void releaseMediaRecorder() { 
     Log.v(TAG, "Releasing media recorder." ); 
     if (mMediaRecorder != null ) { 
       mMediaRecorder.reset(); 
       if (mCamera != null ) { 
             if (Integer.parseInt(Build.VERSION.SDK) >= 8
                 VideoCameraNew2.reconnect(mCamera); 
             mCamera.release(); 
             mCamera = null
      
       mMediaRecorder.release(); 
       mMediaRecorder = null
    
  
      
   public void onError(MediaRecorder mr, int what, int extra) { 
     if (what == MediaRecorder.MEDIA_RECORDER_ERROR_UNKNOWN) { 
       finish(); 
    
   }
?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
private void releaseMediaRecorder() {
     Log.v(TAG, "Releasing media recorder." );
     if (mMediaRecorder != null ) {
       mMediaRecorder.reset();
       if (mCamera != null ) {
             if (Integer.parseInt(Build.VERSION.SDK) >= 8 )
                 VideoCameraNew2.reconnect(mCamera);
             mCamera.release();
             mCamera = null ;
       }
       mMediaRecorder.release();
       mMediaRecorder = null ;
     }
   }
     
   public void onError(MediaRecorder mr, int what, int extra) {
     if (what == MediaRecorder.MEDIA_RECORDER_ERROR_UNKNOWN) {
       finish();
     }
   }
?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
private void stopVideoRecording() { 
     Log.v(TAG, "stopVideoRecording" ); 
     if (mMediaRecorderRecording || mMediaRecorder != null ) { 
         Receiver.listener_video = null
         t.interrupt(); 
       RtpStreamSender.delay = 0
 
       if (mMediaRecorderRecording && mMediaRecorder != null ) { 
         try
           mMediaRecorder.setOnErrorListener( null ); 
           mMediaRecorder.setOnInfoListener( null ); 
           mMediaRecorder.stop(); 
         } catch (RuntimeException e) { 
           Log.e(TAG, "stop fail: " + e.getMessage()); 
        
 
         mMediaRecorderRecording = false
      
       releaseMediaRecorder(); 
    
   }

如有疑问请留言或者到本站社区交流讨论,感谢阅读,希望能帮助到大家,谢谢大家对本站的支持! 。

原文链接:http://blog.csdn.net/zhyooo123/article/details/6750061 。

最后此篇关于java中初始化MediaRecorder的实现方法的文章就讲到这里了,如果你想了解更多关于java中初始化MediaRecorder的实现方法的内容请搜索CFSDN的文章或继续浏览相关文章,希望大家以后支持我的博客! 。

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com