forked from shadowfacts/Tusker
46 lines
1.2 KiB
Swift
46 lines
1.2 KiB
Swift
//
|
|
// GalleryPlayerViewController.swift
|
|
// Tusker
|
|
//
|
|
// Created by Shadowfacts on 6/21/20.
|
|
// Copyright © 2020 Shadowfacts. All rights reserved.
|
|
//
|
|
|
|
import UIKit
|
|
import AVKit
|
|
import Pachyderm
|
|
|
|
class GalleryPlayerViewController: AVPlayerViewController {
|
|
|
|
var attachment: Attachment!
|
|
|
|
override func viewDidLoad() {
|
|
super.viewDidLoad()
|
|
|
|
allowsPictureInPicturePlayback = true
|
|
}
|
|
|
|
override func viewDidAppear(_ animated: Bool) {
|
|
super.viewDidAppear(animated)
|
|
|
|
// starting while audio is already playing from another app often takes nearly a second,
|
|
// so do it on a background thread as to not block the UI
|
|
DispatchQueue.global(qos: .userInitiated).async {
|
|
AudioSessionHelper.enable()
|
|
AudioSessionHelper.setVideoPlayback()
|
|
}
|
|
}
|
|
|
|
override func viewWillDisappear(_ animated: Bool) {
|
|
super.viewWillDisappear(animated)
|
|
|
|
// starting often takes around half a second,
|
|
// so do it on a background thread as to not block the UI
|
|
DispatchQueue.global(qos: .userInitiated).async {
|
|
AudioSessionHelper.setDefault()
|
|
AudioSessionHelper.disable()
|
|
}
|
|
}
|
|
|
|
}
|