I am trying to view a live streaming by motion on my Raspberry Pi through an Android App written with Android Studio...I have compound this code using mplayer:
public class MainActivity extends ActionBarActivity implements SurfaceHolder.Callback, MediaPlayer.OnPreparedListener {
private MediaPlayer mediaPlayer;
private SurfaceHolder vidHolder;
private SurfaceView vidSurface;
String vidAddress = "http://www.example.com/";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
vidSurface = (SurfaceView) findViewById(R.id.surfView);
vidHolder = vidSurface.getHolder();
vidHolder.addCallback(this);
}
@Override
public void surfaceCreated(SurfaceHolder holder) {
try {
mediaPlayer = new MediaPlayer();
mediaPlayer.setDisplay(vidHolder);
mediaPlayer.setDataSource(vidAddress);
mediaPlayer.prepare();
mediaPlayer.setOnPreparedListener(this);
mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
}
catch(Exception e){
e.printStackTrace();
}
}
@Override
public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
}
@Override
public void surfaceDestroyed(SurfaceHolder holder) {
}
@Override
public void onPrepared(MediaPlayer mp) {
mediaPlayer.start();
}
}
But it does not work. If I put an url of a streaming video (not live) for example: www.something.com/vid.mp4 it works. (Yes, I have added internet permission on manifest). Anyone could help me? Thanks!
I noticed you are inserting a web address without a file at the end - that might be your cause. Motion uses the file stream.mjpg, so the local address by default would be http://hostip:8081/stream.mjpg
Source: http://www.lavrsen.dk/foswiki/bin/view/Motion/MotionGuideBasicFeatures#Webcam_Server