2017-04-17 2 views
1

을 파괴 할 때 진행 막대를 업데이트 유지, 나는 비디오 파일을 다운로드하고 다운로드 진행 상황 추적하기 위해이 기능을 사용뷰가 내 이온 2 응용 프로그램에서

download() 
{ 
    this.progressbar=true; 
    this.downloadbutton=false; 
    this.fileTransfer.download('https://...videoURL....mp4', this.file.dataDirectory + 'path/to/downloads/test.mp4').then((entry) => { 
     console.log('download complete: ' + entry.toURL()); 
     this.progressbar=false; 
     this.startbutton=true; 
    }, (error) => { 
     console.log('error'); 
     console.log(error); 
    }); 

    this.fileTransfer.onProgress(progressEvent => { 
     if (progressEvent.lengthComputable) { 
      console.log("### Download percentage ###: "+Math.round((progressEvent.loaded/progressEvent.total)*100)); 
      this.setpercentage((progressEvent.loaded/progressEvent.total) * 100); 
     } else { 
     } 
    }); 

} 

setpercentage 사용을, 나는 페이지에 진행 막대를 업데이트

setpercentage(perc) { 
     this.loadProgress = Math.round(perc); 
     this.ref.detectChanges(); 
    } 

이 모두 정상적으로 작동합니다. 사용자가 멀리 (뒤로) 탐색하면보기가 삭제됩니다. 비디오는 계속 다운로드되지만 비디오가 계속 다운로드되는 동안 페이지로 돌아 가면 진행률 막대가 업데이트되지 않습니다. 값은 0 %로 유지됩니다.

보기가 파괴 된 경우에도 어떻게 진행 막대를 계속 업데이트 할 수 있습니까?

기본적으로이 pagetab과 동일한 기능을 사용하고 싶습니다. 사용자가 다른 탭 사이를 이동할 때 이전 탭의 모든 내용이 기억됩니다.

도움을 주시면 감사하겠습니다.

는 업데이트 :

사용자가 처음 페이지로 이동, "영화를 다운로드"라는 버튼이있다 :

다음은 응용 프로그램의 작동 방식을 좀 더 정보입니다. 사용자가 클릭하면 download()이 호출됩니다. this.progressbar=true;은 진행 표시 줄을 표시하지만 this.downloadbutton=false은 다운로드 단추를 표시하지 않습니다. 다운로드가 완료되면 진행률 막대가 사라지고 (this.progressbar=false;) "동영상 재생"버튼이 나타납니다 (this.startbutton=true;). 문제은 사용자가 다운로드 버튼을 클릭 한 다음 탐색하여이 페이지로 돌아 오면 모든 것이 재설정 된 것처럼 보입니다 (동영상이 다운로드되었지만). 다운로드 버튼이 다시 표시됩니다.

답변

1

뷰가 파괴 될 때이 오류 또는 관찰

this.fileTransfer.download('https://...videoURL....mp4', 
    this.file.dataDirectory + 'path/to/downloads/test.mp4').then((entry) => { 
     console.log('download complete: ' + entry.toURL()); 
     this.progressbar=false; 
     this.startbutton=true; 
    }, (error) => { 
     this.progressbar=false; ////////////////////////////////// 
     console.log('error'); 
     console.log(error); 
    }); 

진행 막대의 상태는 전혀 변경해야 가능한 작업의 완료로 전환 중. 또한

뷰가

ngOnDestroy(){ 
     this.progressbar=false; //////// 
} 

업데이트 1과 동일한 경우에는 처리 ngOnDestroy()주기 후크 구현

파괴되어

다운로드 방법의 구문은 다음과 같은

아래 께
fileTransfer.download(
    sourceURL, 
    targetURL, 
    successcallback, 
    errorCallBack, 
    trustAllHosts, 
    options) 

원본, 대상, successcallback, 필수 매개 변수 Docs

업데이트 구문에 따라 방법

는 errorCallBack 있습니다.

+0

답장을 보내 주셔서 감사합니다. 제안 된 조정으로 프로젝트를 빌드하려고하면 빌드 오류가 발생합니다. '제공된 매개 변수가 호출 대상의 서명과 일치하지 않습니다.' – binoculars

+0

이 오류가 발생한 줄은 무엇입니까? – Aravind

+0

'this.fileTransfer.download ('https : //...videoURL....mp4', ' – binoculars

관련 문제