Read video stored on android native storage in my Ionic app

前端 未结 2 512
深忆病人
深忆病人 2020-12-02 02:49

I am developing ionic 3 app that download videos from server to the device\'s native storage . i used this URL to save file:

let externalDir = this.file.exte         


        
2条回答
  •  生来不讨喜
    2020-12-02 03:19

    If you want to access any file for native storage of mobile. Then you have to create a local server of the folder you want the access of.

    https://ionicframework.com/docs/native/httpd

    constructor(public file:File, public ngZone : NgZone, public httpd :Httpd){
    }
    
    startLocalServe(){
    
        let options: HttpdOptions = {
          www_root: this.file.externalDataDirectory.replace('file://',''),
          port: 9000,
          localhost_only: true //if you want to create multiple localhost then false  
        };
    
        this.httpd.startServer(options).subscribe(url => {
          console.log('Server is live',url); //Server is live http://127.0.0.0.1:9000
          this.ngZone.run(()=>{
            this.localServeUrl = url;
          })
    
        },error => {
          console.log('Fail to start Server : ',JSON.stringify(error));
        });
      }
    

    Now you will able to localserveUrl as src="http://127.0.0.0.1:9000/VideoTest1/0.mp4"

    put the code startLocalServe in app.component.ts

    this.platform.ready().then(()=>{
    startLocalServe();
    });
    

提交回复
热议问题