How to play viedo streaming in android

Put your problem here if it does not fit any of the other categories.

How to play viedo streaming in android

Postby swathi » Sat Jun 06, 2009 12:31 pm

I wrote the following code for video streaming in android,But it doesn't work...didn't get any o/p.



public class VideoPlay extends Activity {

private String _videoPath;
private MediaPlayer _mp;
private static final String TAG = "Video";

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

_videoPath = "http://16.181.151.159/video/funnydog.wmv";
// _videoPath="http://www.youtube.com/watch?v=apEuFdzP5ZU";

getWindow().setFormat(PixelFormat.TRANSLUCENT);

LinearLayout layout = new LinearLayout(getBaseContext());
layout.setLayoutParams(new LinearLayout.LayoutParams
(LinearLayout.LayoutParams.FILL_PARENT,LinearLayout.LayoutParams.FILL_PARENT));

SurfaceView sview = new SurfaceView(getBaseContext());
sview.setLayoutParams(new LinearLayout.LayoutParams(320,180));
sview.getHolder().addCallback(new surfaceHolderCallback());

layout.addView(sview);
setContentView(layout);
}

class surfaceHolderCallback implements SurfaceHolder.Callback {
public void surfaceCreated(SurfaceHolder holder) {
try {
_mp = new MediaPlayer();
_mp.setDataSource(_videoPath);
_mp.setDisplay(holder);

_mp.setOnPreparedListener(new
MediaPlayer.OnPreparedListener() {
public void onPrepared(MediaPlayer mediaPlayer) {
mediaPlayer.start();
}
});

_mp.setOnErrorListener(new MediaPlayer.OnErrorListener
() {
public boolean onError(MediaPlayer mediaPlayer,int
i, int i1) {
Log.e(TAG, Integer.toString(i));
return false;
}
});

_mp.prepareAsync();

} catch (Exception ex) {
Log.e(TAG, ex.getMessage());
}
}

public void surfaceChanged(SurfaceHolder surfaceHolder, int i,
int i1, int i2) {
}

public void surfaceDestroyed(SurfaceHolder surfaceHolder) {
_mp.stop();
_mp.release();
}
}

}


can anybody tell me how to do video streaming in android, or is there any mistakes in my code.
swathi
Freshman
Freshman
 
Posts: 4
Joined: Tue May 12, 2009 7:39 am

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: No registered users and 15 guests