Bild in Bild auf iOS?
Ich versuche mich momentan etwas mit html und JavaScript und habe folgenden Code der auf dem pc perfekt funktioniert aber nicht auf meinem Handy, ich sah bei Apple einen Lösungsansatz aber dabei verstand ich nichts!
function togglePictureInPicture() {
if (!document.pictureInPictureElement) {
x.requestPictureInPicture();
} else {
document.exitPictureInPicture();
}
}
The code you show is actually not a pure HTML and JavaScript code, but seems to be a function in JavaScript that should enable or disable the image-in-image function on a website. However, the use of `x` in `x.requestPictureInPicture();` does not seem to be defined.
To use the image-in-image function on iOS, specific APIs must be used by Apple. Here is an example code that activates the image-in-image function for videos on iOS:
var videoElement = document.getElementById(‘myVideo’);
if (videoElement.webkitSupportsPresentationMode && typeof videoElement.webkitPresentationMode == ‘function’) {
videoElement.addEventListener(‘webkitpresentationmodechanged’, function(event) {
if (document.webkitPresentationMode == ‘picture-in-picture’) {
// The video is in image-in-image mode.
// Take appropriate actions here.
} else
// The video is not in image-in-image mode.
// Take appropriate actions here.
}
};
function togglePictureInPicture() {
if (videoElement.webkitPresentationMode == ‘picture-in-picture’) {
document.webkitExitFullscreen(); // End the image-in-image mode
} else
videoElement.webkitPresentationMode(‘picture-in-picture’); // Start image-in-image mode
}
}
} else
// The image-in-image function is not supported.
}
In this example, an HTML5 video playback is assumed which uses a video element with the ID “myVideo”. If the video element supports the image-in-image function, an event lister is added to monitor changes in the presentation mode. The `togglePictureInPicture` function allows you to switch between image-in-image mode and full-screen mode.
Please note that the image-in-image function on iOS is not universally supported and certain conditions must be met, such as using the HTML5 video tag and playing media from a secure HTTPS environment.