I want to implement video streaming using the Wowza server. So, is there any tutorial that how Wowza works for Android devices?
Videos are stored at server side. So, to fetch video using URL and play it on Android. I tried some examples, but I got error, "Sorry, this video can not be played". I am using URL enter code here
definst/mp4:amazons3/XXX/XXX_42u9Ug_MP4Akon-Beautifulft.ColbyO%27Donis%2CKardinalOffishall(1).mp4/manifest.f4m">http://XXXX.amazonaws.com/vods3/ definst /mp4:amazons3/XXX/XXX_42u9Ug_MP4Akon-Beautifulft.ColbyO%27Donis%2CKardinalOffishall(1).mp4/manifest.f4m.
Below is the source code.
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.main);
mVideoView = (VideoView) findViewById(R.id.surface_view);
mPath = (EditText) findViewById(R.id.path);
mPath.setText("http://XXXX.amazonaws.com/vods3/_definst_/mp4:amazons3/XXX/XXXX_42u9Ug_MP4Akon-Beautifulft.ColbyO%27Donis%2CKardinalOffishall(1).mp4/manifest.f4m");
mPlay = (ImageButton) findViewById(R.id.play);
mPause = (ImageButton) findViewById(R.id.pause);
mReset = (ImageButton) findViewById(R.id.reset);
mStop = (ImageButton) findViewById(R.id.stop);
mPlay.setOnClickListener(new OnClickListener() {
public void onClick(View view) {
playVideo();
}
});
mPause.setOnClickListener(new OnClickListener() {
public void onClick(View view) {
if (mVideoView != null) {
mVideoView.pause();
}
}
});
mReset.setOnClickListener(new OnClickListener() {
public void onClick(View view) {
if (mVideoView != null) {
mVideoView.seekTo(0);
}
}
});
mStop.setOnClickListener(new OnClickListener() {
public void onClick(View view) {
if (mVideoView != null) {
current = null;
mVideoView.stopPlayback();
}
}
});
runOnUiThread(new Runnable() {
public void run() {
playVideo();
}
});
}
private void playVideo() {
try {
final String path = mPath.getText().toString();
Log.v(TAG, "path: " + path);
if (path == null || path.length() == 0) {
Toast.makeText(VideoStreamingDemo.this,
"File URL/path is empty", Toast.LENGTH_LONG).show();
} else {
// If the path has not changed, just start the media player
if (path.equals(current) && mVideoView != null) {
mVideoView.start();
mVideoView.requestFocus();
return;
}
current = path;
mVideoView.setVideoPath(getDataSource(path));
mVideoView.start();
mVideoView.requestFocus();
}
} catch (Exception e) {
Log.e(TAG, "error: " + e.getMessage(), e);
if (mVideoView != null) {
mVideoView.stopPlayback();
}
}
}
private String getDataSource(String path) throws IOException {
if (!URLUtil.isNetworkUrl(path)) {
return path;
} else {
URL url = new URL(path);
URLConnection cn = url.openConnection();
cn.connect();
InputStream stream = cn.getInputStream();
if (stream == null)
throw new RuntimeException("stream is null");
File temp = File.createTempFile("mediaplayertmp", "dat");
temp.deleteOnExit();
String tempPath = temp.getAbsolutePath();
FileOutputStream out = new FileOutputStream(temp);
byte buf[] = new byte[128];
do {
int numread = stream.read(buf);
if (numread <= 0)
break;
out.write(buf, 0, numread);
} while (true);
try {
stream.close();
} catch (IOException ex) {
Log.e(TAG, "error: " + ex.getMessage(), ex);
}
return tempPath;
}
}
To play videos on Android devices use "RTSP" and the url format is
rtsp://wowzaserveripaddress:1935/applicationname/mp4:directoryname/videofilename.mp4
or
rtsp://wowzaserveripaddress:1935/applicationname/mp4:videofilename.mp4
For Example
rtsp://192.168.1.11:1935/vod/mp4:sample.mp4
Ensure that your wowza server is running before your testing
Try this in your native android player or MXPlayer
RTSP is a real headache try [ http://server_ip:1935/vod/definst/ 'foldername'/mp4:'videoname'.mp4/playlist.m3u8] ex: my video name 'camness.mp4' inside folder 'trend'. then my url is [ http://server_ip:1935/vod/definst/trend/mp4:camness.mp4/playlist.m3u8]
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.