I'm have implemented the picture in picture function for my web project on angular.
This is the basic component for it.
export class PlayerPipComponent implements OnInit {
@Input() video!: HTMLVideoElement;
isPlayerErrorOpen = false;
constructor(@Inject(DOCUMENT) private document: Document, private dialog: MatDialog) {}
ngOnInit(): void {}
async togglePip(): Promise<void> {
try {
if (this.document.pictureInPictureEnabled) {
if (this.video !== this.document.pictureInPictureElement) {
await this.video.requestPictureInPicture();
} else {
await this.document.exitPictureInPicture();
}
} else {
this.showGeneralError('000', "This browser doesn't have Picture in Picture enabled.");
}
} catch (error) {
console.log('Error', error);
this.showGeneralError('000', error);
}
}
I was trying to add the controls for seekforward and seekbackward, but for some reason they don't seem to work on it. But the previoustrack and nexttrack controls work fine.
navigator.mediaSession.setActionHandler('previoustrack', (details) => {
// Go to previous track
console.log('previostrack', details);
});
navigator.mediaSession.setActionHandler('nexttrack', (details) => {
// Go to next track
console.log('nextrack', details);
});
Just adding these few lines, it shows the controls in the picture in picture. But if add these next ones, it doesn't show the seekbackward o forward controls.
navigator.mediaSession.setActionHandler('seekbackward', function (details) {
// Do something
});
navigator.mediaSession.setActionHandler('seekforward', function (details) {
//Do something
});
Does anyone know if they are just not supported? Or if you could point out what I'm doing wrong, I would be very thankful.