我正在通过 AsyncTask 从 ftp 服务器下载视频并将其保存在设备上。下载后(onPostExecute)我想在我的活动中直接在视频视图中播放视频,但问题是不能调用我的 playVideo 方法,因为它不是静态的,而是我试图在 onResume() 方法中调用它,使用 get() 方法,但是我的 ASynctask 中的进度条当时没有显示,并且应用程序后来崩溃了。有什么建议吗?
先感谢您
公共类 PlayStreamedVideo 扩展 Activity {
final String TAG = "PlayStreamedVideo";
private VideoView videoView;
private MediaController mediaController;
private DownloadVideo download;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.guessvideo);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
download = new DownloadVideo(PlayStreamedVideo.this, SAVE_PATH);
download.execute();
}
@Override
protected void onResume(){
try {
while(download.get() == false){
Log.d(TAG, "1");
}
playVideo();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ExecutionException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
super.onResume();
}
public void playVideo() {
try {
videoView = (VideoView) findViewById(R.id.streamedVideoSurface);
mediaController = new MediaController(this);
videoView.setVideoURI(Uri.parse(SAVE_PATH));
videoView.setMediaController(mediaController);
videoView.start();
} catch (Exception e) {
// Log.e(TAG, "error: " + e.getMessage(), e);
}
}