Live Streaming video

imenandroid
Messages postés
12
Date d'inscription
vendredi 14 février 2014
Statut
Membre
Dernière intervention
25 février 2014
- Modifié par imenandroid le 25/02/2014 à 14:10
Bonjour,
j'ai un grand probleme et j'espére que vous m'aidez a le resoudre
j'ai implementé une application android qui bascule automatiquement sur la caméra de l'emulateur android
voila mon code

import java.io.IOException;

import android.content.Context;
import android.hardware.Camera;
import android.view.SurfaceHolder;
import android.view.SurfaceView;

public class Preview extends SurfaceView implements SurfaceHolder.Callback{
SurfaceHolder mHolder;
Camera mCamera;

Preview(Context context) {
super(context);

// Install a SurfaceHolder.Callback so we get notified when the
// underlying surface is created and destroyed.
mHolder = getHolder();
mHolder.addCallback(this);
mHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
}

public void surfaceCreated(SurfaceHolder holder) {
// The Surface has been created, acquire the camera and tell it where
// to draw.
mCamera = Camera.open();
try {
mCamera.setPreviewDisplay(holder);
} catch (IOException exception) {
mCamera.release();
mCamera = null;
// TODO: add more exception handling logic here
}
}

public void surfaceDestroyed(SurfaceHolder holder) {
// Surface will be destroyed when we return, so stop the preview.
// Because the CameraDevice object is not a shared resource, it's very
// important to release it when the activity is paused.
mCamera.stopPreview();
mCamera = null;
}

public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) {
// Now that the size is known, set up the camera parameters and begin
// the preview.
Camera.Parameters parameters = mCamera.getParameters();
parameters.setPreviewSize(w, h);
mCamera.setParameters(parameters);
mCamera.startPreview();
}


}


import java.util.ArrayList;
import java.util.List;

import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;

import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.Window;
import android.widget.Toast;
import com.google.gson.Gson;

public class MainActivity extends Activity {
private Preview mPreview;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Hide the window title.
requestWindowFeature(Window.FEATURE_NO_TITLE);

// Create our Preview view and set it as the content of our activity.
mPreview = new Preview(this);
setContentView(mPreview);
HttpPost httppost;
HttpResponse response;
HttpClient httpclient;
List<NameValuePair> nameValuePairs;
httpclient=new DefaultHttpClient();
try{

nameValuePairs = new ArrayList<NameValuePair>();
Gson gson = new Gson();
String jsonAdd = gson.toJson(mPreview);
nameValuePairs.add(new BasicNameValuePair("cam",jsonAdd ));
httppost= new HttpPost("http://10.0.2.2/www/page1.php");
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
response = httpclient.execute(httppost);
Toast.makeText(this, "connexion reussite!", Toast.LENGTH_SHORT)
.show();
}
catch(Exception e){ Toast.makeText(this, "connexion échoué!", Toast.LENGTH_SHORT)
.show();}
}



}

et mon but principale est d'associer cette camera a ma page php local,j'ai utilisé le gson comme il est montionné dans l'activité MainActivity et
voici mon code php
!DOCTYPE html> 
<html lang="fr">
<head>
<title>Vidéo HTML5 </title>
<meta charset="UTF-8">

</head>
<body>
<h1>Balise video en html5</h1>
<?php $TaskAddress = $_POST['cam'];
$jAddress = json_decode($TaskAddress);
echo($jAddress);?>
<video id="myvideo" src=<?php echo $jAddress;?>. controls="controls" width="612px" poster="tof.jpg" height="550px" ">

Your browser does not support html5 video.
</video>
</body>
</html>

Mais j'ai pas arrivé a l'affiché