Skip to content

MediaSession not supported by TypeScript 2.3.4 #19473

Closed
@pablo-gonzalez

Description

@pablo-gonzalez

TypeScript Version: 2.3.4

Code

  navigator.mediaSession.metadata = new MediaMetadata({
    title: "Podcast Episode Title",
    artist: "Podcast Host",
    album: "Podcast Name",
    artwork: [{src: "podcast.jpg"}]
  });
  navigator.mediaSession.setActionHandler('play', function() {});
  navigator.mediaSession.setActionHandler('pause', function() {});
  navigator.mediaSession.setActionHandler('seekbackward', function() {});
  navigator.mediaSession.setActionHandler('seekforward', function() {});
  navigator.mediaSession.setActionHandler('previoustrack', function() {});
  navigator.mediaSession.setActionHandler('nexttrack', function() {});
}

Expected behavior:
MediaSession and MediaMetadata should be recognized by Typescript.

https://developer.mozilla.org/en-US/docs/Web/API/MediaSession
https://developers.google.com/web/updates/2017/02/media-session

Actual behavior:
Visual Studio Code Version 1.17.2 is showing the following Problems after saving the ts file:

message: 'Property 'mediaSession' does not exist on type 'Navigator'.'
message: 'Cannot find name 'MediaMetadata'.'

System information:

pablo@pablo-Inspiron-7520:~/projects/fpt3$ ionic info
cli packages: (/usr/lib/node_modules)

@ionic/cli-utils  : 1.13.1
ionic (Ionic CLI) : 3.13.2

global packages:

cordova (Cordova CLI) : 6.5.0

local packages:

@ionic/app-scripts : 2.1.4
Cordova Platforms  : android 6.1.2 browser 4.1.0
Ionic Framework    : ionic-angular 3.7.1

System:

Android SDK Tools : 25.2.5
Node              : v7.10.0
npm               : 3.10.10
OS                : Linux 4.4

Misc:

backend : pro

As a workround I have installed @types/wicg-mediasession:
https://www.npmjs.com/package/@types/wicg-mediasession

Activity

changed the title [-]MediaSession not supported by TypeScript using Ionic 2[/-] [+]MediaSession not supported by TypeScript 2.3.4[/+] on Oct 25, 2017
added
Domain: lib.d.tsThe issue relates to the different libraries shipped with TypeScript
SuggestionAn idea for TypeScript
on Oct 25, 2017
mhegazy

mhegazy commented on Oct 25, 2017

@mhegazy
Contributor

PRs welcomed. You can find more information about contributing lib.d.ts fixes at https://github.com/Microsoft/TypeScript/blob/master/CONTRIBUTING.md#contributing-libdts-fixes.

pablo-gonzalez

pablo-gonzalez commented on Oct 26, 2017

@pablo-gonzalez
Author

I would be glad to help in the future. Currently I do not have the enough knowledge to contribute.
However I have given a workaround to help other people facing the same issue.

Best regards,
Pablo

added this to the Community milestone on Oct 26, 2017
aareeph

aareeph commented on Dec 5, 2018

@aareeph

Hi @pablo-gonzalez, I am getting exactly same error while trying to use MediaSession in Typescript. I tried installing @types/wicg-mediasession as well but couldn't resolve the issue.

Here's the response from the developer when I tried to use this library in my Angular project:
w3c/mediasession#206 (comment)

Thanks!

joaovct

joaovct commented on Oct 25, 2020

@joaovct

(Exactly) 3 years after this issue, the only "solution" is using // @ts-ignore?

jsmith

jsmith commented on Nov 8, 2020

@jsmith

The "solution" is not // @ts-ignore but installing @types/wicg-mediasession as stated by @pablo-gonzalez

npm install --save-dev @types/wicg-mediasession

I'm using it now and it's working fantastic!

MetaMmodern

MetaMmodern commented on Jan 1, 2021

@MetaMmodern

The "solution" is not // @ts-ignore but installing @types/wicg-mediasession as stated by @pablo-gonzalez

npm install --save-dev @types/wicg-mediasession

I'm using it now and it's working fantastic!

+1, this is working, the issue may be closed imo. Also add this to some docs so it is google'd better)
@jsmith thank you anf Happy New Year)

sanderschnydrig

sanderschnydrig commented on Jun 28, 2022

@sanderschnydrig

I installed @types/wicg-mediasession but its not doing anything to solve the error for me.

Edit: using // @ts-ignore which is working

5 remaining items

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Domain: lib.d.tsThe issue relates to the different libraries shipped with TypeScriptHelp WantedYou can do thisSuggestionAn idea for TypeScript

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

      Development

      Participants

      @jakebailey@RyanCavanaugh@mhegazy@aareeph@pablo-gonzalez

      Issue actions

        MediaSession not supported by TypeScript 2.3.4 · Issue #19473 · microsoft/TypeScript