|
275 | 275 | end if |
276 | 276 | end sub |
277 | 277 |
|
| 278 | +' Determines if custom subtitles should be used for the current selection |
| 279 | +' Custom subtitles should only be used for external subtitles when the user has enabled the setting |
| 280 | +function shouldUseCustomSubtitlesForCurrentSelection() as boolean |
| 281 | + ' First check if the user has enabled custom subtitles at all |
| 282 | + if not m.global.session.user.settings["playback.subs.custom"] |
| 283 | + m.log.debug("Custom subtitles disabled by user setting") |
| 284 | + return false |
| 285 | + end if |
| 286 | + |
| 287 | + ' If no subtitle is currently selected, no need for custom subtitles |
| 288 | + if not isValid(m.top.selectedSubtitle) or m.top.selectedSubtitle = -1 |
| 289 | + m.log.debug("No subtitle selected", m.top.selectedSubtitle) |
| 290 | + return false |
| 291 | + end if |
| 292 | + |
| 293 | + ' Find the selected subtitle in the fullSubtitleData |
| 294 | + selectedSubtitle = invalid |
| 295 | + if isValid(m.top.fullSubtitleData) |
| 296 | + for each subtitle in m.top.fullSubtitleData |
| 297 | + if subtitle.Index = m.top.selectedSubtitle |
| 298 | + selectedSubtitle = subtitle |
| 299 | + exit for |
| 300 | + end if |
| 301 | + end for |
| 302 | + end if |
| 303 | + |
| 304 | + ' If we found the selected subtitle and it's external, use custom subtitles |
| 305 | + if isValid(selectedSubtitle) and isValid(selectedSubtitle.IsExternal) |
| 306 | + m.log.debug("Subtitle found", selectedSubtitle.IsExternal, selectedSubtitle.Index) |
| 307 | + return selectedSubtitle.IsExternal |
| 308 | + end if |
| 309 | + |
| 310 | + m.log.debug("Selected subtitle not found in fullSubtitleData or invalid IsExternal flag") |
| 311 | + ' Default to false (use native Roku subtitles) |
| 312 | + return false |
| 313 | +end function |
| 314 | + |
278 | 315 | ' Only setup caption items if captions are allowed |
279 | 316 | sub onAllowCaptionsChange() |
280 | 317 | if not m.top.allowCaptions then return |
|
287 | 324 | m.top.observeField("subtitleTrack", "loadCaption") |
288 | 325 | m.top.observeField("globalCaptionMode", "toggleCaption") |
289 | 326 |
|
290 | | - if m.global.session.user.settings["playback.subs.custom"] |
291 | | - m.top.suppressCaptions = true |
292 | | - toggleCaption() |
293 | | - else |
294 | | - m.top.suppressCaptions = false |
295 | | - end if |
296 | 327 | end sub |
297 | 328 |
|
298 | 329 | ' Set caption url to server subtitle track |
299 | 330 | sub loadCaption() |
| 331 | + m.log.debug("loadCaption() called", m.top.subtitleTrack, m.top.suppressCaptions) |
300 | 332 | if m.top.suppressCaptions |
| 333 | + m.log.debug("Setting captionTask.url", m.top.subtitleTrack) |
301 | 334 | m.captionTask.url = m.top.subtitleTrack |
302 | 335 | end if |
303 | 336 | end sub |
|
331 | 364 | ' If previous sustitle was encoded, then we need to a video stop/start to change subtitle content |
332 | 365 | if m.top.previousSubtitleWasEncoded then switchWithoutRefresh = false |
333 | 366 |
|
| 367 | + ' Update custom subtitle behavior based on new selection |
| 368 | + if m.top.allowCaptions |
| 369 | + shouldUseCustomSubtitles = shouldUseCustomSubtitlesForCurrentSelection() |
| 370 | + |
| 371 | + m.log.debug("Subtitle changed", shouldUseCustomSubtitles, m.top.suppressCaptions) |
| 372 | + |
| 373 | + if shouldUseCustomSubtitles <> m.top.suppressCaptions |
| 374 | + ' Custom subtitle mode has changed, update it |
| 375 | + m.log.debug("Changing custom subtitle mode to", shouldUseCustomSubtitles) |
| 376 | + m.top.suppressCaptions = shouldUseCustomSubtitles |
| 377 | + if m.top.suppressCaptions |
| 378 | + toggleCaption() |
| 379 | + end if |
| 380 | + end if |
| 381 | + end if |
| 382 | + |
334 | 383 | if switchWithoutRefresh then return |
335 | 384 |
|
336 | 385 | ' Save the current video position |
|
460 | 509 |
|
461 | 510 | m.top.selectedSubtitle = videoContent[0].selectedSubtitle |
462 | 511 |
|
| 512 | + ' Update custom subtitle behavior based on the selected subtitle |
| 513 | + if m.top.allowCaptions |
| 514 | + shouldUseCustomSubtitles = shouldUseCustomSubtitlesForCurrentSelection() |
| 515 | + m.top.suppressCaptions = shouldUseCustomSubtitles |
| 516 | + if m.top.suppressCaptions |
| 517 | + toggleCaption() |
| 518 | + end if |
| 519 | + end if |
| 520 | + |
463 | 521 | m.top.observeField("selectedSubtitle", "onSubtitleChange") |
464 | 522 |
|
465 | 523 | if isValid(m.top.audioIndex) |
|
526 | 584 |
|
527 | 585 | ' align button with bottom right edge with 5% padding |
528 | 586 | boundingRect = m.notifyButtons.localBoundingRect() |
529 | | - print "boundingRect =", boundingRect |
530 | 587 |
|
531 | 588 | m.notifyButtons.translation = [ |
532 | 589 | 1920 - (1920 * 0.05), |
|
613 | 670 | ' |
614 | 671 | ' When Video Player state changes |
615 | 672 | sub onState() |
616 | | - m.log.debug("start onState()", m.top.state) |
| 673 | + m.log.debug("start onState", m.top.state) |
617 | 674 | if isValid(m.captionTask) |
618 | 675 | m.captionTask.playerState = m.top.state + m.top.globalCaptionMode |
619 | 676 | end if |
|
683 | 740 | else |
684 | 741 | m.log.warning("Unhandled state", m.top.state, m.playReported, m.playFinished) |
685 | 742 | end if |
686 | | - m.log.debug("end onState()", m.top.state) |
| 743 | + m.log.debug("end onState", m.top.state) |
687 | 744 | end sub |
688 | 745 |
|
689 | 746 | ' |
690 | 747 | ' Report playback to server |
691 | 748 | sub ReportPlayback(state = "update" as string) |
692 | 749 | if not isValid(m.top.position) then return |
693 | 750 |
|
694 | | - m.log.debug("start ReportPlayback()", state, int(m.top.position)) |
| 751 | + m.log.debug("start ReportPlayback", state, int(m.top.position)) |
695 | 752 |
|
696 | 753 | params = { |
697 | 754 | "ItemId": m.top.id, |
|
708 | 765 | end if |
709 | 766 |
|
710 | 767 | if (state = "stop" or state = "finished") and isValid(m.originalClosedCaptionState) |
711 | | - m.log.debug("ReportPlayback() setting", m.top.globalCaptionMode, "back to", m.originalClosedCaptionState) |
| 768 | + m.log.debug("ReportPlayback setting", m.top.globalCaptionMode, "back to", m.originalClosedCaptionState) |
712 | 769 | m.top.globalCaptionMode = m.originalClosedCaptionState |
713 | 770 | m.originalClosedCaptionState = invalid |
714 | 771 | end if |
|
718 | 775 | playstateTask.setFields({ status: state, params: params }) |
719 | 776 | playstateTask.control = "RUN" |
720 | 777 |
|
721 | | - m.log.debug("end ReportPlayback()", state, int(m.top.position)) |
| 778 | + m.log.debug("end ReportPlayback", state, int(m.top.position)) |
722 | 779 | end sub |
723 | 780 |
|
724 | 781 | ' |
|
0 commit comments