使用离子播放存储在设备本地存储中的视频

时间:2018-07-04 06:08:16

标签: ionic3 local-storage

我想播放下载并存储在设备本地存储中的视频。我正在使用ionic3。我无法使用该路径播放视频。在我的屏幕上,我正在接收(回呼错误消息)流式传输失败消息。之后什么也没发生。

这是我的做法: a)在本地下载并存储。

    download(link) {
    this.storage.get('Videos').then((val) => {
        console.log('Your age is', val);
    });

    console.log(link.articlefile2)
    console.log("video link","http://xxx.xx.xx.xxx/MentorMe/public/"+link.articlefile2);

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

    const fileTransfer: TransferObject = this.transfer.create();
    const imageLocation ='http://xxx.xx.xx.xxx/MentorMe/public/'+link.articlefile2;
    console.log("img",imageLocation)

    fileTransfer.download(imageLocation, this.storageDirectory + 'dizzy.mp4').then((entry) => {
        console.log("imgsfdgddshfgj============",this.storageDirectory)   
        const alertSuccess = this.alertCtrl.create({
        title: `Download Succeeded!`,
        subTitle: `successfully downloaded to: ${entry.toURL()}`,
        buttons: ['Ok']
    });
    this.storage.set("Videos", {postid:link.postid,status:"downloaded"}) 
    this.videoLocation=imageLocation;
    this.playvideo(this.storageDirectory);
}, (error) => {
    const alertFailure = this.alertCtrl.create({
        title: `Download Failed!`,
        subTitle: `was not downloaded. Error code: ${error}`,
        buttons: ['Ok']
    });

    alertFailure.present();
});

b)播放视频:

  playvideo(link) {
      console.log("http://xxx.xx.xx.xxx/MentorMe/public/",link);
      let  mystring = link;
      console.log("my strin g::::::",mystring);

      let options: StreamingVideoOptions = {
        successCallback: () => {  true; console.log('Video played'); },
      errorCallback: (e) => { console.log("Error streaming") },
       orientation: "portrait"
    };
    this.streamingMedia.playVideo(mystring, options);
 }

0 个答案:

没有答案