0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

【Swift】AVPlayerItemが原因でクラッシュする

Posted at

はじめに

動画を扱う実装をしてるときに遭遇したエラーの解決方法を記録しておきます。

エラー

An AVPlayerItem cannot be associated with more than one instance of AVPlayer

スクリーンショット 2023-03-16 13.20.45.png

どういう時に発生するのか

このような変数にAVPlayerItemを格納してViewに表示しているとします。

@Published var playerItem: AVPlayerItem?

このように中身を入れ替えると発生しました

playerItem = AVPlayerItem(asset: アセット1)
playerItem = AVPlayerItem(asset: アセット2)

解決策

一度、nilにして再度代入するとエラーが出なくなりました

playerItem = AVPlayerItem(asset: アセット1)
playerItem = nil
playerItem = AVPlayerItem(asset: アセット2)

おわり

この解決方法が適切かは分かりませんが、一応解決することができました

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?