我在macOS应用程序中创建了一个非常简单的AVPlayer。
perf %>%
spread(Task, Performance, fill = 0)
#> # A tibble: 5 x 6
#> person_id Task1 Task2 Task3 Task4 Task5
#> * <int> <dbl> <dbl> <dbl> <dbl> <dbl>
#> 1 1 1 1 1 1 1
#> 2 2 2 2 2 2 2
#> 3 3 3 3 3 3 3
#> 4 4 4 4 4 4 4
#> 5 5 5 5 5 5 5
它基本上可以正常工作,但玩家会在发布时自动播放,但不应该。即使我在import Cocoa
import AVKit
import AVFoundation
class ViewController: NSViewController {
@IBOutlet var playerView: AVPlayerView!
override func viewDidLoad() {
super.viewDidLoad()
let videoPath = URL(fileURLWithPath: "myPath/myFile.mp4")
let videoPlayer = AVPlayer(url: videoPath)
playerView.player = videoPlayer
}
}
末尾添加playerView.player?.pause()
,也会自动播放。
我做错了什么?
答案 0 :(得分:1)
您至少应该将AVPlayer
放在ViewWillAppear()
功能中,暂停playerView.player
会暂停整个视图 - 而是暂停videoPlayer
:
videoPlayer.pause()
在playerView.player = videoPlayer
之后添加;那么你的代码就是:
override func viewWillAppear() {
super.viewWillAppear()
let videoPath = URL(fileURLWithPath: "myPath/myFile.mp4")
let videoPlayer = AVPlayer(url: videoPath)
playerView.player = videoPlayer
videoPlayer.pause()
}