我正在开发一款可以解析Youtube和Dailymotion网页的Android应用,并渲染其视频网址,但缓存速度并不稳定。
有时,视频通过其网站原生播放器快速缓存,但在我的Android视频中缓慢缓存。
我如何解决问题,以及这两种播放视频的方式之间有什么区别?
private class isConnected extends AsyncTask<String, Void, Boolean> {
Boolean result;
public isConnected(Boolean r)
{
result = r;
}
protected Boolean doInBackground(String... params) {
HttpClient client = new DefaultHttpClient();
String getURL = params[0];
HttpGet get = new HttpGet(getURL);
HttpResponse responseGet = null;
try {
responseGet = client.execute(get);
} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
Toast.makeText(getBaseContext(), "Error:" + e.getMessage(), Toast.LENGTH_LONG).show();
return false;
} catch (IOException e) {
// TODO Auto-generated catch block
//e.printStackTrace();
Toast.makeText(getBaseContext(), "Error:" + e.getMessage(), Toast.LENGTH_LONG).show();
return false;
}
if(responseGet.getStatusLine().getStatusCode() == HttpStatus.SC_OK)
result = true;
else
result = false;
return result;
}
protected void onPostExecute(Boolean r) {
// here you have the result
result = r;
}
}
VideoView videoView;
String URL;
videoView.setVideoPath(URL);
myVideoView.setOnPreparedListener(
new OnPreparedListener() {
@Override
public void onPrepared(MediaPlayer arg0) {
arg0.setOnBufferingUpdateListener(new OnBufferingUpdateListener(){
@Override
public void onBufferingUpdate(MediaPlayer mp, int percent) {
// TODO Auto-generated method stub
Log.d("123","Buffer Percentage = " + percent);
}});
// TODO Auto-generated method stub
new isConnected(video_ready).execute(URL);
if (!video_ready)
{
progDailog.dismiss();
AlertDialog.Builder alert = new AlertDialog.Builder(HomeActivity.this);
alert.setTitle("Warning").setMessage("The URL of video is incorrect.").setNeutralButton("OK", null);
alert.create().show();
}
if (progDailog.isShowing())
{
progDailog.dismiss();
}
videoView.start();
}
});