URL에서 비디오를 다운로드하는 코드가 있습니다. AsyncTask를 사용하고 있습니다. 이제 내가하고 싶은 일은 다운로드중인 비디오의 진행률 대화 상자를 통해 사용자에게 알리는 것입니다. 또는 "Downloading Video 2 of 10"과 같은 것입니다. 나는 다음과 같은 코드를 사용하고 있습니다 :Android 오류 : 다운로드중인 파일을 사용자에게 알립니다.
android.view.ViewRoot $ CalledFromWrongThreadException : 견해를 만질 수있는 뷰 계층 구조를 생성 만 원래 스레드
//DOWNLOAD VIDEOS
private class downloadVideosAsync extends AsyncTask <String, String, String>{
protected void onPreExecute(){
super.onPreExecute();
MyActivity.this.mProgressDialog.setMessage("Downloading Videos...");
}
@Override
protected String doInBackground(String... strings){
try{
ArrayList<String> VideoNames = VideosM.getVideoNames();
ArrayList<String> VideoUrls = VideosM.getVideoUrls();
File vidFile = null;
int videoNamesLenght = VideoNames.size();
int x;
for(x = 0; x < videoNamesLenght; x++) {
//download video
String[] videoName = VideoNames.get(x).split("/");
String currentFile = videoName[0] + "." + videoName[1];
String currentFileURL = VideoUrls.get(x) + VideoNames.get(x);
vidFile = new File(Environment.getExternalStorageDirectory()
+ "/Engagia/Downloads/Videos/", currentFile);
if(!vidFile.exists()){
int curr_vid = x + 1;
String ui_msg = "Downloading Videos " + curr_vid + " of " + videoNamesLenght + "...";
MyActivity.this.mProgressDialog.setMessage(ui_msg);
VideosC.downloadVideoFile(currentFile, currentFileURL, vidFile);
}
}
}catch (NullPointerException e){
Log.e(LOG_TAG, e.toString());
}catch(Exception e){
Log.e(LOG_TAG, e.toString());
}
return null;
}
@Override
protected void onPostExecute(String lenghtOfFile) {
new downloadSlideshowsAsync().execute();
}
}
위의 코드는 나에게 오류를 제공합니다.
편집 : 나는 또한 시도
:
runOnUiThread(new Runnable() {
public void run() {
String ui_msg = "Downloading Videos " + curr_vid + " of " + videoNamesLenght + "...";
Engagia.this.mProgressDialog.setMessage(ui_msg);
Log.v("VideosController.java", ui_msg);
}
});
를하지만 나에게 같은 오류를 제공합니다 ...
감사 @utopianheaven 안드로이드 개발자 사이트에 대한 세부 사항을 찾을 수 있지만, 그것은 나에게 같은 오류 .... – MiD
오 남자, 작동, 난 그냥 MyActivity.this을 제거했다을 제공합니다. mProgressDialog.setMessage ("내부 비디오 루프."); 이후 for (x = 0; x
MiD