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 :

Enregistrement de vidéo sur android


Sujet :

Android

  1. #1
    Membre à l'essai
    Femme Profil pro
    Ingénieur avant-vente
    Inscrit en
    Janvier 2013
    Messages
    25
    Détails du profil
    Informations personnelles :
    Sexe : Femme

    Informations professionnelles :
    Activité : Ingénieur avant-vente
    Secteur : Industrie

    Informations forums :
    Inscription : Janvier 2013
    Messages : 25
    Points : 19
    Points
    19
    Par défaut Enregistrement de vidéo sur android
    Bonsoir ,
    Je veux faire l'enregistrement de flux d'une camera ip et sauvegarder le vidéo .Est ce qu'il y a quelqu'un qui peux m'aider pour réaliser cette application ?

  2. #2
    Membre à l'essai
    Femme Profil pro
    Ingénieur avant-vente
    Inscrit en
    Janvier 2013
    Messages
    25
    Détails du profil
    Informations personnelles :
    Sexe : Femme

    Informations professionnelles :
    Activité : Ingénieur avant-vente
    Secteur : Industrie

    Informations forums :
    Inscription : Janvier 2013
    Messages : 25
    Points : 19
    Points
    19
    Par défaut Enregistrement de vidéo à partir du camera du smartphone
    Bonjour ,
    pour le moment j'essaye de développer l'application d'enregistrement de vidéo du camera du smartphone
    j'ai essayé avec ce code mais lors de l'appui sur le bouton start l'application se ferme Voici mon code : je travaille avec android 2.3.3
    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
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    package com.example.main;
     
    import java.io.File;
    import java.io.IOException;
     
    import android.hardware.Camera;
    import android.media.MediaRecorder;
    import android.media.MediaRecorder.OnErrorListener;
    import android.media.MediaRecorder.OnInfoListener;
    import android.os.Bundle;
    import android.os.Environment;
    import android.app.Activity;
    import android.content.Intent;
    import android.util.Log;
    import android.view.Menu;
    import android.view.SurfaceHolder;
    import android.view.View;
    import android.view.View.OnClickListener;
    import android.widget.Button;
    import android.widget.MediaController;
    import android.widget.TextView;
    import android.widget.Toast;
    import android.widget.VideoView;
     
    public class Main extends Activity implements SurfaceHolder.Callback,OnInfoListener,OnErrorListener{
     
     
    	private Button initBtn=null;
    	private Button startBtn=null;
    	private Button stopBtn=null;
    	private Button playBtn=null;
    	private Button stopPlayBtn=null;
    	private TextView recordingmsg=null;
    	private VideoView videoView=null;
    	private SurfaceHolder holder=null;
    	private Camera camera=null;
    	private static final String Tag="RecordVideo";
    	private MediaRecorder recorder=null;
    	private String outputFileName;
    	@Override
    	protected void onCreate(Bundle savedInstanceState) {
    		super.onCreate(savedInstanceState);
    		setContentView(R.layout.main);
     
    		//get references to UI elements
    		initBtn=(Button)findViewById(R.id.init);
    		startBtn=(Button)findViewById(R.id.start);
    		stopBtn=(Button)findViewById(R.id.stop);
    		playBtn=(Button)findViewById(R.id.review);
    		stopPlayBtn=(Button)findViewById(R.id.stopreview);
    		recordingmsg=(TextView)findViewById(R.id.recording);
    		videoView=(VideoView)this.findViewById(R.id.videoview);
    	}
     
    	public void buttonTapped(View view)
    	{
    		switch(view.getId()){
    		case R.id.init:
    			initRecorder();
    			break;
    		case R.id.start:
    			BeginRecording();
    			break;
    		case R.id.stop:
    			stopRecording();
    			break;
    		case R.id.review:
    			playRecording();
    			break;
    		case R.id.stopreview:
    			StopPlayBack();
    			break;
    		}
    	}
     
    	private void StopPlayBack(){
    	videoView.stopPlayback();	
    	}
     
    	private void playRecording() {
    	MediaController mc=new MediaController(this);
    	videoView.setMediaController(mc);
    	videoView.setVideoPath(outputFileName);
    	videoView.start();
    	stopPlayBtn.setEnabled(true);
    	}
     
    	private void stopRecording() {
    		if (recorder!=null){
    			//recorder.setOnErrorListener(null);
    			//recorder.setOnInfoListener(null);
    			try {
    				recorder.stop();
    			}
    			catch(IllegalStateException e){
    				Log.e(Tag, "Got illegalStateException in stop recording" );
    			}
    			//releaseRecorder();
    			recordingmsg.setText("");
    			//releaseCamera();
    			startBtn.setEnabled(false);
    			stopBtn.setEnabled(false);
    			playBtn.setEnabled(true);
    		}
     
    	}
     
    	private void releaseCamera() {
    		if (camera!=null)
    		try{
    			camera.reconnect();
    		}catch(IOException e){
    			e.printStackTrace();
    		}
    		camera.release();
    		camera=null;
    	}
     
    	private void releaseRecorder() {
    		if(recorder!=null){
    			try{
    				camera.reconnect();
    			}catch(IOException e){
    				e.printStackTrace();
    			}
    			camera.release();
    			camera=null;
    		}
     
    	}
     
    	private void BeginRecording() {
    	recorder.setOnInfoListener(this);
    	recorder.setOnErrorListener(this);
    	recorder.start();
    	recordingmsg.setText("recording");
    	Toast.makeText(getApplicationContext(),"Begin Recording", Toast.LENGTH_LONG).show();
    	startBtn.setEnabled(false);
    	stopBtn.setEnabled(true);
    	}
     
    	public void initRecorder(){
    		if(recorder!=null)return;
    		outputFileName=Environment.getExternalStorageDirectory()+"/vidéooutput.mp4";
    		File outFile=new File(outputFileName);
    		if(outFile.exists())outFile.delete();
    		try{
    			camera.stopPreview();
    			camera.unlock();	
    			recorder =new MediaRecorder();
    			recorder.setCamera(camera);
    			recorder.setAudioSource(MediaRecorder.AudioSource.CAMCORDER);
    			recorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
    			recorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
    			recorder.setVideoSize(176, 144);
    			recorder.setVideoFrameRate(15);
    			recorder.setVideoEncoder(MediaRecorder.VideoEncoder.MPEG_4_SP);
    			recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
    			recorder.setMaxDuration(7000);//limit to 7 second
    			recorder.setPreviewDisplay(holder.getSurface());
    			recorder.setOutputFile(outputFileName);
     
    		//recorder.prepare();
    		Log.v(Tag, "Media recorder initialised");
    		initBtn.setEnabled(false);
    		startBtn.setEnabled(true);
    		}
    		catch(Exception e) {
    			Log.v(Tag, "Media recorder failed to initialise");
    			e.printStackTrace();
    		}
    	}
     
    	@Override
    	public boolean onCreateOptionsMenu(Menu menu) {
    		// Inflate the menu; this adds items to the action bar if it is present.
    		getMenuInflater().inflate(R.menu.main, menu);
    		return true;
    	}
    	@Override
    	public void surfaceChanged(SurfaceHolder arg0, int arg1, int arg2, int arg3) {
    		// TODO Auto-generated method stub
     
    	}
    	@Override
    	public void surfaceCreated(SurfaceHolder arg0) {
    		Log.v(Tag, "in surface created");
    		try{
    			camera.setPreviewDisplay(holder);
    			camera.startPreview();
    		} catch(IOException e){
    			Log.v(Tag, "Could not start the preview");
    			e.printStackTrace();
    		}
    		initBtn.setEnabled(true);
    		}
     
     
     
     
    	@Override
    	public void surfaceDestroyed(SurfaceHolder arg0) {
    		// TODO Auto-generated method stub
     
    	}
     
    	@Override
    	public void onInfo(MediaRecorder mr, int what, int extra) {
    		Log.i(Tag, "got a recording event");
    		if (what==MediaRecorder.MEDIA_RECORDER_INFO_MAX_DURATION_REACHED)
    		{
    			Log.i(Tag, "...max duration reached");
     
    		stopRecording();
    		Toast.makeText(this, "Recording limit  has not reached Stopping the recording", Toast.LENGTH_SHORT).show();
    		}
    	}
     
    	@Override
    	public void onError(MediaRecorder mr, int what, int extra) {
    		Log.e(Tag, "got a reacording error");
    		stopRecording();
    		Toast.makeText(this, "Recording error  has  occured Stopping the recording", Toast.LENGTH_SHORT).show();
    	}
    @Override
    protected void onResume() {
    	Log.v(Tag,"onResume");
    	super.onResume();
    	initBtn.setEnabled(false);
    	startBtn.setEnabled(false);
    	stopBtn.setEnabled(false);
    	playBtn.setEnabled(false);
    	stopPlayBtn.setEnabled(false);
    	if(!initCamera())
    	finish();
    }
     
    private boolean initCamera() {
    try{
    	camera=Camera.open();
    	Camera.Parameters camParams=camera.getParameters();
    	camera.lock();
    	holder=videoView.getHolder();
    	holder.addCallback(this);
    	holder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
     
    }
    catch(RuntimeException re){
    	Log.v(Tag, "could not initialise the camera");
    	re.printStackTrace();
    	return false;
    }
    	return true;
    }
    }
    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
     
    <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"
        tools:context=".MainActivity" >
     
        <Button
            android:id="@+id/review"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_alignParentRight="true"
            android:layout_below="@+id/button1"
            android:layout_marginTop="52dp"
            android:onClick="buttonTapped"
            android:text="Review" />
     
        <TextView
            android:id="@+id/recording"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@+id/button5"
            android:layout_marginRight="37dp"
     
            android:text=""
            android:textAppearance="?android:attr/textAppearanceLarge" />
     
        <Button
            android:id="@+id/start"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_alignParentRight="true"
            android:onClick="buttonTapped"
            android:text="Start" />
     
     
     
        <Button
            android:id="@+id/stopreview"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_alignParentRight="true"
            android:onClick="buttonTapped"
            android:layout_below="@+id/review"
            android:text="stopReview" />
     
        <Button
            android:id="@+id/stop"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_alignParentRight="true"
            android:onClick="buttonTapped"
            android:layout_below="@+id/stopreview"
            android:text="Stop" />
     
        <Button
            android:id="@+id/init"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_alignParentRight="true"
            android:onClick="buttonTapped"
            android:layout_below="@+id/stop"
            android:text="initialize" />
     
        <TextView
            android:id="@+id/recording"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_below="@+id/init"
            android:text="Large Text"
            android:textAppearance="?android:attr/textAppearanceLarge" />
     
        <VideoView
            android:id="@+id/videoview"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_below="@+id/recording"
            android:layout_marginTop="32dp" />
     
    </RelativeLayout>
    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
     
    <?xml version="1.0" encoding="utf-8"?>
    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
        package="com.example.main"
        android:versionCode="1"
        android:versionName="1.0" >
     
        <uses-sdk
            android:minSdkVersion="10"
            android:targetSdkVersion="16" />
    <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"/>
     
        <application
            android:allowBackup="true"
            android:icon="@drawable/ic_launcher"
            android:label="@string/app_name"
            android:theme="@style/AppTheme">
            <activity
                android:name="com.example.main.Main"
                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>
    est ce que vous pouvez m'aider ?

  3. #3
    Membre éprouvé
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Janvier 2007
    Messages
    697
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 36
    Localisation : France, Calvados (Basse Normandie)

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : High Tech - Produits et services télécom et Internet

    Informations forums :
    Inscription : Janvier 2007
    Messages : 697
    Points : 1 241
    Points
    1 241
    Par défaut
    L'enregistrement doit se faire à partir d'une camera IP ou du smartphone ?
    Dans le premier cas qu'elle est le format du flux ? J'ai fait un projet comme ça. Je me connectais à la caméra avec une simple socket, je parsais le flux (MJPEG dans mon cas) et je le transformais en AVI. La création de l'AVI n'est pas une opération triviale et il n'y a pas d'API android pour le faire (pareil pour les autres formats vidéos) donc si tu as besoin je peux te fournir la classe que j'ai adaptée (MP moi).

    Pour ton problème, sans la stacktrace, on ne va pas pouvoir faire grand chose...

Discussions similaires

  1. Réponses: 0
    Dernier message: 13/05/2015, 11h40
  2. Enregistrement de vidéo sur android
    Par marwwwwwa dans le forum Android
    Réponses: 1
    Dernier message: 08/04/2013, 18h55
  3. Player de vidéos sur Android
    Par isou9001 dans le forum Android
    Réponses: 0
    Dernier message: 04/11/2012, 16h53
  4. Enregistrer une vidéo sur le disque dur
    Par bbattia dans le forum WinDev
    Réponses: 2
    Dernier message: 25/08/2011, 00h26
  5. [CS3] Enregistrer une vidéo sur le disque dur
    Par vouvou dans le forum Flash
    Réponses: 1
    Dernier message: 03/08/2010, 12h06

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