【问题标题】:How can I access picture in picture related function in angular typescript?如何在角度打字稿中访问画中画相关功能?
【发布时间】:2019-08-12 01:34:20
【问题描述】:

当我尝试使用画中画相关的任何功能时,我会收到这些错误。错误是HtmlVideoElement 类型不存在此功能。如何在 Angular 中访问 c​​hrome 的这些新功能?

【问题讨论】:

    标签: javascript angular google-chrome javascript-objects


    【解决方案1】:

    我声明了一个新的interface,它扩展了HTMLVideoElement 接口。这是一种解决方法,但可以消除 VScode 智能感知中的错误。

    【讨论】:

    【解决方案2】:

    PiP API (还没有?)由 Typescript 生成的 DOM 类型 (https://github.com/microsoft/TypeScript-DOM-lib-generator) 公开。同时,您可以在自己的代码中使用 PiP API 扩充现有的 DOM 类型:

    declare global {
      interface HTMLVideoElement {
        requestPictureInPicture: () => Promise<any>;
      }
    
      interface Document {
        exitPictureInPicture: () => Promise<any>;
      }
    }
    

    【讨论】:

      猜你喜欢
      • 2016-09-07
      • 2017-12-19
      • 2020-10-03
      • 2016-07-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-10-07
      相关资源
      最近更新 更多