Angular 4/5使用GET请求加载视频/ mp4内容

时间:2018-02-01 14:37:39

标签: angular video mp4

我尝试使用get请求从安全API加载mp4视频文件。

在我们的API文档中:

请求(GET):/ cma / contentmanager / getfragment?fragmentid = x 标题:关键 - "授权",价值 - "持票人"

响应(JSON): 内容类型 - 视频/ mp4

我做了以下事情:

  1. 在请求服务中创建加载程序
  2. 
    
    public getVideo(url:string): Observable<any> {
            const headers = new HttpHeaders({ 'Authorization': 'Bearer ' + this.authenticationService.token, 'Content-Type': 'video/mp4' });
            const options = { headers: headers };
            return this.http.get(url, options);
        }
    &#13;
    &#13;
    &#13;

    1. 在组件中运行加载程序
    2. &#13;
      &#13;
      export class MovieComponent implements OnInit {
      
      @ViewChild('videoPlayer') videoplayer: any;
      videoUrl: string = '/cma/contentmanager/getfragment?fragmentid=';
      videoSource: any;
      
      private loadVideo(id) {
              this.requestService.getVideo(this.videoUrl+''+id) // get video for fragment from secure API
                  .subscribe(data => {
                      this.videoSource = data;
                  })
      }
      }
      &#13;
      &#13;
      &#13;

      1. 将videoplayer添加到html
      2. &#13;
        &#13;
        <span (click)="loadVideo(dataItem.Id)">Load {{ dataItem.Name }}</span>
        
        <div class="video">
            {{videoSource}}
        </div>
        &#13;
        &#13;
        &#13;

        但视频丢失了。我怎么了?

0 个答案:

没有答案