Closed
Description
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
[-]MediaSession not supported by TypeScript using Ionic 2[/-][+]MediaSession not supported by TypeScript 2.3.4[/+]mhegazy commentedon Oct 25, 2017
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 commentedon Oct 26, 2017
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
aareeph commentedon Dec 5, 2018
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 commentedon Oct 25, 2020
(Exactly) 3 years after this issue, the only "solution" is using // @ts-ignore?
jsmith commentedon Nov 8, 2020
The "solution" is not
// @ts-ignore
but installing @types/wicg-mediasession as stated by @pablo-gonzalezI'm using it now and it's working fantastic!
MetaMmodern commentedon Jan 1, 2021
+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 commentedon Jun 28, 2022
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