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

Test app improvements for seek and close caption #16

Open
emdobrin opened this issue Mar 20, 2023 · 0 comments
Open

Test app improvements for seek and close caption #16

emdobrin opened this issue Mar 20, 2023 · 0 comments
Labels
task Item that can be completed as a standalone code change or is part of an epic.Used by issue template

Comments

@emdobrin
Copy link
Contributor

Task description

Improve test apps for Media for Edge Network extension with examples for:

Additional implementation details or code snippet(s)

func detectCCChange() {
    guard let currentItem = self.player.currentItem else { return }
    let asset = currentItem.asset

    if #available(iOS 15.0, *) {
      asset.loadMediaSelectionGroup(for: AVMediaCharacteristic.legible, completionHandler: { group, _ in
        guard let group = group else { return }
        self.detectCCStatus(item: currentItem, group: group)
      })
    } else {
      guard let group = asset.mediaSelectionGroup(forMediaCharacteristic: AVMediaCharacteristic.legible) else { return }
      detectCCStatus(item: currentItem, group: group)
    }
  }

  func detectCCStatus(item: AVPlayerItem, group: AVMediaSelectionGroup) {
    let option = item.currentMediaSelection.selectedMediaOption(in: group)
    let ccActive = (option != nil)
    if self._isCCActive != ccActive {
      self._isCCActive = ccActive
      var info: [String: Any] = [:]
      info["ccActive"] = self._isCCActive
      NotificationCenter.default.post(name: NSNotification.Name(rawValue: PlayerEvent.PLAYER_EVENT_CC_CHANGE), object: self, userInfo: info)
    }
  }func detectCCChange() {
    guard let currentItem = self.player.currentItem else { return }
    let asset = currentItem.asset

    if #available(iOS 15.0, *) {
      asset.loadMediaSelectionGroup(for: AVMediaCharacteristic.legible, completionHandler: { group, _ in
        guard let group = group else { return }
        self.detectCCStatus(item: currentItem, group: group)
      })
    } else {
      guard let group = asset.mediaSelectionGroup(forMediaCharacteristic: AVMediaCharacteristic.legible) else { return }
      detectCCStatus(item: currentItem, group: group)
    }
  }

  func detectCCStatus(item: AVPlayerItem, group: AVMediaSelectionGroup) {
    let option = item.currentMediaSelection.selectedMediaOption(in: group)
    let ccActive = (option != nil)
    if self._isCCActive != ccActive {
      self._isCCActive = ccActive
      var info: [String: Any] = [:]
      info["ccActive"] = self._isCCActive
      NotificationCenter.default.post(name: NSNotification.Name(rawValue: PlayerEvent.PLAYER_EVENT_CC_CHANGE), object: self, userInfo: info)
    }
  }
@emdobrin emdobrin added the task Item that can be completed as a standalone code change or is part of an epic.Used by issue template label Mar 20, 2023
@emdobrin emdobrin added this to the v1.0.0 milestone Apr 20, 2023
@addb addb self-assigned this May 19, 2023
@emdobrin emdobrin removed this from the v4.0.0 milestone Jun 7, 2023
@addb addb removed their assignment Oct 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
task Item that can be completed as a standalone code change or is part of an epic.Used by issue template
Projects
None yet
Development

No branches or pull requests

2 participants