Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support mediaSession #526

Open
lebanggit opened this issue Jan 5, 2023 · 1 comment
Open

Support mediaSession #526

lebanggit opened this issue Jan 5, 2023 · 1 comment
Labels
Bug: Needs Confirmation 🧐 Bugs that are reported, but needs to be confirmed and replicated.

Comments

@lebanggit
Copy link

Issue Description

https://developer.mozilla.org/en-US/docs/Web/API/Media_Session_API

New standard for all modern devices.

Expected Behavior

sync controlers with device.

ex: iOS control center

Steps To Reproduce

`// https://stackoverflow.com/questions/73993512/web-audio-player-ios-next-song-previous-song-buttons-are-not-in-control-cent
// https://developer.mozilla.org/en-US/docs/Web/API/MediaSession
if ('mediaSession' in navigator) {
var setMediaMetadata = function() {
currentSong = Amplitude.getActiveSongMetadata();
navigator.mediaSession.metadata = new MediaMetadata({
title: currentSong.name,
artist: currentSong.artist,
album: currentSong.album,
artwork: [{ src: currentSong.cover_art_url }]
});
};

        var audioElement = Amplitude.getAudio();

        audioElement.addEventListener('loadstart', (event) => {
            setMediaMetadata();
        });

        navigator.mediaSession.setActionHandler('play', () => { Amplitude.play(); });
        navigator.mediaSession.setActionHandler('pause', () => { Amplitude.pause(); });
        navigator.mediaSession.setActionHandler('stop', () => { Amplitude.stop(); });
        navigator.mediaSession.setActionHandler('seekto', (seconds) => { Amplitude.skipTo(seconds, Amplitude.getActiveIndex()); });
        navigator.mediaSession.setActionHandler('previoustrack', () => { Amplitude.prev(); });
        navigator.mediaSession.setActionHandler('nexttrack', () => { Amplitude.next(); });
    }`

AmplitudeJS Version

5.3.2

Browser Information

No response

Link To Where Your Issue Can Be Reproduced

No response

Anything else?

No response

@lebanggit lebanggit added the Bug: Needs Confirmation 🧐 Bugs that are reported, but needs to be confirmed and replicated. label Jan 5, 2023
@Ry3yr
Copy link

Ry3yr commented Jan 15, 2023

For properly implemented mediaSESSION see:
https://codepen.io/ciberst/pen/wvjxjOR

Might have to be amended to work with amplitudejs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug: Needs Confirmation 🧐 Bugs that are reported, but needs to be confirmed and replicated.
Projects
None yet
Development

No branches or pull requests

2 participants