I am having an application to download video on sdcard from url. I refer this link. But this link contains the url as .mp4 format. I have to download news feed videos. My format is not .mp4 format. It will be mostly .swf. The url of mine is,
http://cdnapi.kaltura.com/index.php/kwidget/wid/_483511/uiconf_id/5590821/entry_id/0_cf39ej0c
I was getting this url by parsing rss feed( news feed).
My code is:
public class MainActivity extends Activity {
public final String TAG = "MainActivity";
private final String PATH = "/sdcard/downloadVideo/";
private final int TIMEOUT_CONNECTION = 5000;// 5sec
private final int TIMEOUT_SOCKET = 300000;// 30sec
//public final String imageURL = "http://www.cbsnews.com/video/watch/?id=50149183n&tag=api";
public final String imageURL = "http://cdnapi.kaltura.com/index.php/kwidget/wid/_483511/uiconf_id/5590821/entry_id/0_cf39ej0c";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
DownloadFromUrl(imageURL, PATH);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
public void DownloadFromUrl(String VideoURL, String fileName) { // this is
// the
// downloader
// method
try {
URL url = new URL(VideoURL);
long startTime = System.currentTimeMillis();
Log.i(TAG, "image download beginning: " + VideoURL);
// Open a connection to that URL.
URLConnection ucon = url.openConnection();
// this timeout affects how long it takes for the app to realize
// there's a connection problem
ucon.setReadTimeout(TIMEOUT_CONNECTION);
ucon.setConnectTimeout(TIMEOUT_SOCKET);
// Define InputStreams to read from the URLConnection.
// uses 3KB download buffer
InputStream is = ucon.getInputStream();
BufferedInputStream inStream = new BufferedInputStream(is, 1024 * 5);
FileOutputStream outStream = new FileOutputStream(fileName);
byte[] buff = new byte[5 * 1024];
// Read bytes (and store them) until there is nothing more to
// read(-1)
int len;
while ((len = inStream.read(buff)) != -1) {
outStream.write(buff, 0, len);
}
// clean up
outStream.flush();
outStream.close();
inStream.close();
Log.i(TAG, "download completed in "
+ ((System.currentTimeMillis() - startTime) / 1000)
+ " sec");
} catch (IOException e) {
Log.d("VideoManager", "Error: " + e);
}
}
}
But I couldn't get this video?
Actually I am trying to achieve video streaming. But I don't know that how to do it.
Am i doing any wrong in my code?
Please give your suggestion to achieve the above.
Thank you in advance!!