无需使用麦克风即可请求访问麦克风-迅速

时间:2018-11-18 13:02:40

标签: swift avplayer microphone

我的应用中的动画(mp4)出现问题。有时(并非始终)启动应用程序时,它请求访问麦克风,但我并不是在应用程序中的任何位置请求一个麦克风。我仅使用AVPlayer播放mp4内容。以下代码是与播放器相关的唯一代码。知道为什么我被要求进行麦克风访问吗?谢谢

import UIKit
import Foundation
import MediaPlayer
import AVKit

class AnimationLaunchscreen: UIViewController {

    var player: AVPlayer?

    override func viewDidLoad() {
        super.viewDidLoad()

        let timer = Timer.scheduledTimer(timeInterval: 6.0, target: self, selector: #selector(timeToMoveOn), userInfo: nil, repeats: false)

        self.loadVideo()

    }

    @objc func timeToMoveOn() {
        self.performSegue(withIdentifier: "goToTableView", sender: self)
    }

    func loadVideo() {

        let path = Bundle.main.path(forResource: "stopwatchAnimation", ofType:"mp4")

        let filePathURL = NSURL.fileURL(withPath: path!)
        let player = AVPlayer(url: filePathURL)
        let playerLayer = AVPlayerLayer(player: player)

        playerLayer.frame = self.view.frame
        playerLayer.videoGravity = AVLayerVideoGravity.resizeAspectFill
        playerLayer.zPosition = -1

        self.view.layer.addSublayer(playerLayer)

        player.seek(to: CMTime.zero)
        player.play()
    }

    override func viewWillAppear(_ animated: Bool) {
        makeStatusBarBlack()
    }

}

1 个答案:

答案 0 :(得分:0)

在此处添加答案,因此比阅读注释更容易找到。这确实似乎仅是模拟器上的错误(https://forums.developer.apple.com/thread/110423)。在设备上运行正常。