Fix rare case where the custom overlay doesn't play

This commit is contained in:
Tommy Chow 2024-08-12 00:17:17 -07:00
parent 1594d40f48
commit 3bcb1c3594
2 changed files with 45 additions and 38 deletions

View file

@ -179,37 +179,37 @@ class VideoOverlay extends StatelessWidget {
),
);
final streamInfo = videoStore.streamInfo;
if (streamInfo == null) {
return Stack(
children: [
Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
backButton,
const Spacer(),
if (videoStore.settingsStore.fullScreen &&
orientation == Orientation.landscape)
chatOverlayButton,
],
),
Align(
alignment: Alignment.bottomRight,
child: Row(
mainAxisAlignment: MainAxisAlignment.end,
children: [
refreshButton,
if (!videoStore.isIPad) rotateButton,
if (orientation == Orientation.landscape) fullScreenButton,
],
),
),
],
);
}
return Observer(
builder: (context) {
final streamInfo = videoStore.streamInfo;
if (streamInfo == null) {
return Stack(
children: [
Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
backButton,
const Spacer(),
if (videoStore.settingsStore.fullScreen &&
orientation == Orientation.landscape)
chatOverlayButton,
],
),
Align(
alignment: Alignment.bottomRight,
child: Row(
mainAxisAlignment: MainAxisAlignment.end,
children: [
refreshButton,
if (!videoStore.isIPad) rotateButton,
if (orientation == Orientation.landscape) fullScreenButton,
],
),
),
],
);
}
return Stack(
children: [
Row(

View file

@ -338,16 +338,23 @@ abstract class VideoStoreBase with Store {
// Add event listeners to notify the JavaScript channels when the video plays and pauses.
try {
videoWebViewController.runJavaScript(
'''document.getElementsByTagName("video")[0].addEventListener("pause", () => {
'''
(function checkVideoElement() {
const videoElement = document.getElementsByTagName("video")[0];
if (videoElement) {
videoElement.addEventListener("pause", () => {
VideoPause.postMessage("video paused");
document.getElementsByTagName("video")[0].textTracks[0].mode = "hidden";
});''',
);
videoWebViewController.runJavaScript(
'''document.getElementsByTagName("video")[0].addEventListener("playing", () => {
VideoPlaying.postMessage("video playing")
document.getElementsByTagName("video")[0].textTracks[0].mode = "hidden";
});''',
videoElement.textTracks[0].mode = "hidden";
});
videoElement.addEventListener("playing", () => {
VideoPlaying.postMessage("video playing");
videoElement.textTracks[0].mode = "hidden";
});
} else {
setTimeout(checkVideoElement, 100); // Check again after 100ms
}
})();
''',
);
if (settingsStore.showOverlay) {
await _hideDefaultOverlay();