0

我正在开发一个可以解析 Youtube 和 Dailymotion 网页并呈现其视频 URL 的 Android 应用程序,但缓冲速度不稳定。

有时,视频通过其网站本机播放器快速缓冲,但在我的 Android Videoview 中缓冲很慢。

我该如何解决这个问题,这两种播放视频的方式有什么区别?

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();

}
});
4

0 回答 0