IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Android Discussion :

MediaRecorder start failed -38


Sujet :

Android

  1. #1
    Membre régulier
    Homme Profil pro
    Développeur .NET
    Inscrit en
    Septembre 2011
    Messages
    142
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Développeur .NET
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Septembre 2011
    Messages : 142
    Points : 81
    Points
    81
    Par défaut MediaRecorder start failed -38
    Bonjour,

    Depuis hier, j'ai cette erreur : MediaRecorder start failed: - 38.

    Code source de l'activity :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
     
    package com.example.testcamera3;
     
    import java.io.IOException;
     
    import android.hardware.Camera;
    import android.hardware.Camera.Parameters;
    import android.media.CamcorderProfile;
    import android.media.MediaRecorder;
    import android.os.Bundle;
    import android.os.Environment;
    import android.app.Activity;
    import android.view.Menu;
    import android.view.MenuItem;
    import android.view.SurfaceHolder;
    import android.view.SurfaceView;
    import android.view.View;
    import android.view.View.OnClickListener;
    import android.widget.Button;
     
    public class VideoStackActivity extends Activity implements SurfaceHolder.Callback {
     
    	private SurfaceHolder surfaceHolder;
    	private SurfaceView surfaceView;
    	public MediaRecorder mrec = new MediaRecorder();
    	private Button startRecording = null;
    	private Camera mCamera;
     
    	@Override
    	protected void onCreate(Bundle savedInstanceState) {
    		super.onCreate(savedInstanceState);
    		setContentView(R.layout.activity_video_stack);
     
    		startRecording = (Button)findViewById(R.id.buttonstart);
    		startRecording.setOnClickListener(new OnClickListener() {
     
    			@Override
    			public void onClick(View arg0) {
     
    					startRecording();
     
     
    			}
     
    		});
     
    		mCamera = Camera.open();
    		surfaceView = (SurfaceView)findViewById(R.id.surface_camera);
    		surfaceHolder = surfaceView.getHolder();
    		surfaceHolder.addCallback(this);
    		surfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
    	}
     
    	@Override
    	public boolean onCreateOptionsMenu(Menu menu) {
    		menu.add(0, 0, 0, "StartRecording");
    		menu.add(0, 1, 0, "StopRecording");
    		return super.onCreateOptionsMenu(menu);
    	}
     
    	@Override
    	public boolean onOptionsItemSelected(MenuItem item) {
    		switch(item.getItemId()) {
    		case 0:
    			try {
    				startRecording();
    			} catch (Exception e) {
    				mrec.release();
    			}
    			break;
    		case 1:
    			mrec.stop();
    			mrec.release();
    			mrec = null;
    			break;
    		default:
    				break;
    		}
    		return super.onOptionsItemSelected(item);
    	}
     
    	protected void startRecording()  {
    		mrec = new MediaRecorder();
     
     
    		mCamera.unlock();
     
     
     
    		mrec.setCamera(mCamera);
     
    		mrec.setPreviewDisplay(surfaceHolder.getSurface());
    		mrec.setVideoSource(MediaRecorder.VideoSource.CAMERA);
    		mrec.setAudioSource(MediaRecorder.AudioSource.MIC);
     
    		mrec.setProfile(CamcorderProfile.get(CamcorderProfile.QUALITY_LOW));
    		mrec.setVideoFrameRate(1);
    		// A tester
    		//mrec.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
    		mrec.setPreviewDisplay(surfaceHolder.getSurface());
    		//ok
    		mrec.setOutputFile(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_MOVIES)+"/test.mp4");
     
     
     
    //		Ok !
    		try {
    			mrec.prepare();
    		} catch (IllegalStateException e) {
    			// TODO Auto-generated catch block
    			e.printStackTrace();
    		} catch (IOException e) {
    			// TODO Auto-generated catch block
    			e.printStackTrace();
    		}
    		mrec.start();
    	}
     
    	protected void stopRecording() {
    		mrec.stop();
    		mrec.reset();
    		mCamera.release();
    	}
     
    	private void releaseMediaRecorder() {
    		if(mrec != null) {
    			mrec.reset();
    			mrec.release();
    			mrec = null;
    			mCamera.lock();
    		}
    	}
     
    	private void releaseCamera() {
    		if(mCamera != null) {
    			mCamera.release();
    			mCamera = null;
    		}
    	}
     
    	@Override
    	public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
     
    	}
     
    	@Override
    	public void surfaceCreated(SurfaceHolder holder) {
    		if(mCamera!=null) {
    			Parameters params = mCamera.getParameters();
    			mCamera.setParameters(params);
    		}
    	}
     
    	@Override
    	public void surfaceDestroyed(SurfaceHolder holder) {
    		if(mCamera != null) {
    			mCamera.stopPreview();
    			mCamera.release();
    		}
    	}
    }
    Du layout :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
     
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:paddingBottom="@dimen/activity_vertical_margin"
        android:paddingLeft="@dimen/activity_horizontal_margin"
        android:paddingRight="@dimen/activity_horizontal_margin"
        android:paddingTop="@dimen/activity_vertical_margin"
        tools:context=".VideoStackActivity" 
        android:orientation="vertical">
     
        <SurfaceView 
            android:id="@+id/surface_camera"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="1"/>
     
        <Button
            android:id="@+id/buttonstart"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
           />
     
    </RelativeLayout>
    Du manifest :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
     
    <?xml version="1.0" encoding="utf-8"?>
    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
        package="com.example.testcamera3"
        android:versionCode="1"
        android:versionName="1.0" >
     
        <uses-permission android:name="android.permission.RECORD_AUDIO" />
        <uses-permission android:name="android.permission.CAMERA" />
        <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
        <uses-permission android:name="android.permission.INTERNET"/>
     
     
        <uses-sdk
            android:minSdkVersion="8"
            android:targetSdkVersion="17" />
     
        <application
            android:allowBackup="true"
            android:icon="@drawable/ic_launcher"
            android:label="@string/app_name"
            android:theme="@style/AppTheme" >
            <activity
                android:name="com.example.testcamera3.VideoStackActivity"
                android:label="@string/app_name" >
                <intent-filter>
                    <action android:name="android.intent.action.MAIN" />
     
                    <category android:name="android.intent.category.LAUNCHER" />
                </intent-filter>
            </activity>
        </application>
     
    </manifest>
    De quoi peut-il s'agir ?

  2. #2
    Membre régulier
    Homme Profil pro
    Développeur .NET
    Inscrit en
    Septembre 2011
    Messages
    142
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Développeur .NET
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Septembre 2011
    Messages : 142
    Points : 81
    Points
    81
    Par défaut
    En éteignant puis rallumant le portable, cela refonctionné...

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Réponses: 13
    Dernier message: 25/10/2009, 13h40
  2. Réponses: 1
    Dernier message: 30/01/2008, 23h10
  3. Réponses: 0
    Dernier message: 22/07/2007, 18h42
  4. Réponses: 8
    Dernier message: 22/11/2006, 08h54
  5. [tomcat] start - publishing failed.
    Par menuge dans le forum Eclipse Java
    Réponses: 1
    Dernier message: 25/10/2006, 17h25

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo