質問編集履歴

2

修正

2017/02/26 10:33

投稿

maslnomy
maslnomy

スコア6

test CHANGED
File without changes
test CHANGED
@@ -97,85 +97,3 @@
97
97
  のいずれかを教えていただければと思います。
98
98
 
99
99
  よろしくお願いします。
100
-
101
-
102
-
103
- 【追加】
104
-
105
- - AVQueueplayerを用いて、音声ファイル再生の終了を検知する方法
106
-
107
- ですが、以下のサイトのコードを見つけました。
108
-
109
- [How to detect when an AVPlayerItem is finished playing?](http://stackoverflow.com/questions/23502581/how-to-detect-when-an-avplayeritem-is-finished-playing)
110
-
111
-
112
-
113
- ```Swift
114
-
115
- class MyVideoPlayingViewController: AVPlayerViewController {
116
-
117
-
118
-
119
- override func viewDidLoad() {
120
-
121
- // Do any additional setup after loading the view.
122
-
123
- super.viewDidLoad()
124
-
125
-
126
-
127
- let videoURL = URL(fileURLWithPath: Bundle.main.path(forResource: "MyVideo",
128
-
129
- ofType: "mp4")!)
130
-
131
- player = AVPlayer(url: videoURL)
132
-
133
-
134
-
135
- NotificationCenter.default.addObserver(self,
136
-
137
- selector: #selector(MyVideoPlayingViewController.animationDidFinish(_:)),
138
-
139
- name: .AVPlayerItemDidPlayToEndTime,
140
-
141
- object: player?.currentItem)
142
-
143
- }
144
-
145
-
146
-
147
- override func viewDidAppear(_ animated: Bool) {
148
-
149
- super.viewDidAppear(animated)
150
-
151
- player?.play()
152
-
153
- }
154
-
155
-
156
-
157
- func animationDidFinish(_ notification: NSNotification) {
158
-
159
- print("Animation did finish")
160
-
161
- }
162
-
163
-
164
-
165
- deinit {
166
-
167
- NotificationCenter.default.removeObserver(self)
168
-
169
- }
170
-
171
-
172
-
173
- }
174
-
175
- ```
176
-
177
- ですが、ここにコメントされている
178
-
179
- 「Good answer but be sure to invoke removeObserver(_:name:object:) before observer or any object specified in addObserver:selector:name:object: is deallocated.」が分からず…
180
-
181
- 上記のコードをそのまま使って良いものでしょうか?

1

追記

2017/02/26 10:33

投稿

maslnomy
maslnomy

スコア6

test CHANGED
File without changes
test CHANGED
@@ -97,3 +97,85 @@
97
97
  のいずれかを教えていただければと思います。
98
98
 
99
99
  よろしくお願いします。
100
+
101
+
102
+
103
+ 【追加】
104
+
105
+ - AVQueueplayerを用いて、音声ファイル再生の終了を検知する方法
106
+
107
+ ですが、以下のサイトのコードを見つけました。
108
+
109
+ [How to detect when an AVPlayerItem is finished playing?](http://stackoverflow.com/questions/23502581/how-to-detect-when-an-avplayeritem-is-finished-playing)
110
+
111
+
112
+
113
+ ```Swift
114
+
115
+ class MyVideoPlayingViewController: AVPlayerViewController {
116
+
117
+
118
+
119
+ override func viewDidLoad() {
120
+
121
+ // Do any additional setup after loading the view.
122
+
123
+ super.viewDidLoad()
124
+
125
+
126
+
127
+ let videoURL = URL(fileURLWithPath: Bundle.main.path(forResource: "MyVideo",
128
+
129
+ ofType: "mp4")!)
130
+
131
+ player = AVPlayer(url: videoURL)
132
+
133
+
134
+
135
+ NotificationCenter.default.addObserver(self,
136
+
137
+ selector: #selector(MyVideoPlayingViewController.animationDidFinish(_:)),
138
+
139
+ name: .AVPlayerItemDidPlayToEndTime,
140
+
141
+ object: player?.currentItem)
142
+
143
+ }
144
+
145
+
146
+
147
+ override func viewDidAppear(_ animated: Bool) {
148
+
149
+ super.viewDidAppear(animated)
150
+
151
+ player?.play()
152
+
153
+ }
154
+
155
+
156
+
157
+ func animationDidFinish(_ notification: NSNotification) {
158
+
159
+ print("Animation did finish")
160
+
161
+ }
162
+
163
+
164
+
165
+ deinit {
166
+
167
+ NotificationCenter.default.removeObserver(self)
168
+
169
+ }
170
+
171
+
172
+
173
+ }
174
+
175
+ ```
176
+
177
+ ですが、ここにコメントされている
178
+
179
+ 「Good answer but be sure to invoke removeObserver(_:name:object:) before observer or any object specified in addObserver:selector:name:object: is deallocated.」が分からず…
180
+
181
+ 上記のコードをそのまま使って良いものでしょうか?