Skip to content

Commit

Permalink
Configure audio session on video playback
Browse files Browse the repository at this point in the history
  • Loading branch information
ismailgulek committed Nov 16, 2022
1 parent 0ffea83 commit 83a2cba
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions ElementX/Sources/Screens/VideoPlayer/VideoPlayerCoordinator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
// limitations under the License.
//

import AVKit
import SwiftUI

struct VideoPlayerCoordinatorParameters {
Expand Down Expand Up @@ -59,6 +60,9 @@ final class VideoPlayerCoordinator: Coordinator, Presentable {

func start() {
MXLog.debug("Did start.")

configureAudioSession(.sharedInstance())

videoPlayerViewModel.callback = { [weak self] action in
guard let self else { return }
MXLog.debug("VideoPlayerViewModel did complete with result: \(action).")
Expand All @@ -78,6 +82,17 @@ final class VideoPlayerCoordinator: Coordinator, Presentable {
}

// MARK: - Private

private func configureAudioSession(_ session: AVAudioSession) {
do {
try session.setCategory(.playback,
mode: .default,
options: [.defaultToSpeaker, .allowBluetooth, .allowBluetoothA2DP])
try session.setActive(true)
} catch {
MXLog.debug("Configure audio session failed: \(error)")
}
}

/// Show an activity indicator whilst loading.
/// - Parameters:
Expand Down

0 comments on commit 83a2cba

Please sign in to comment.