回答編集履歴
6
訂正
answer
CHANGED
@@ -3,40 +3,41 @@
|
|
3
3
|
|
4
4
|

|
5
5
|
|
6
|
-
で、
|
6
|
+
で、不具合は音を鳴らす画面から他の画面に遷移時、音を止める処理を実行しない場合に起こるようで、
|
7
|
-
適当でおすすめしませんが↓で回避はできますね。
|
8
|
-
|
7
|
+
きちんと音を止める処理をすれば、遷移しても正常に作動するようです。
|
8
|
+
goMenuを通らずにもどったり、他の画面に遷移するとかの処理が入っていると思うので、原因はそのへんではないでしょうか?
|
9
9
|
|
10
|
-
|
11
10
|
```swuft
|
12
11
|
|
13
|
-
class
|
12
|
+
class SViewContoroller: UIViewController {
|
14
|
-
// アウトレットをつないで
|
15
|
-
@IBOutlet weak var startBtn: UIButton!
|
16
13
|
|
17
14
|
var soundID: Int = 1000
|
18
|
-
|
15
|
+
|
19
|
-
|
16
|
+
override func viewDidAppear(_ animated: Bool) {
|
17
|
+
super.viewDidAppear(animated)
|
20
|
-
|
18
|
+
self.startSystemSound()
|
21
|
-
AudioServicesAddSystemSoundCompletion(systemSoundID, nil, nil, { (systemSoundID, nil) -> Void in
|
22
|
-
AudioServicesPlaySystemSound(systemSoundID)
|
23
|
-
}, nil)
|
24
|
-
AudioServicesPlaySystemSound(systemSoundID)
|
25
|
-
// 再生中はタップできなくする
|
26
|
-
startBtn.isEnabled = false
|
27
19
|
}
|
28
20
|
|
21
|
+
|
29
|
-
@IBAction func
|
22
|
+
@IBAction func transition() {
|
30
|
-
stopSystemSound()
|
23
|
+
self.stopSystemSound()
|
24
|
+
let fVC = self.storyboard?.instantiateViewController(withIdentifier: "FViewController") as! FViewController
|
25
|
+
self.present(fVC, animated: true, completion: nil)
|
26
|
+
|
31
27
|
}
|
32
28
|
|
29
|
+
func startSystemSound() {
|
30
|
+
let systemSoundID = SystemSoundID(soundID)
|
31
|
+
AudioServicesAddSystemSoundCompletion(systemSoundID, nil, nil, { (systemSoundID, nil) -> Void in
|
32
|
+
AudioServicesPlaySystemSound(systemSoundID)
|
33
|
+
}, nil)
|
34
|
+
AudioServicesPlaySystemSound(systemSoundID)
|
35
|
+
}
|
36
|
+
|
33
37
|
func stopSystemSound() {
|
38
|
+
// 画面遷移する際に必ずこの処理を通せば音の再生に限定すれば支障はなさそう
|
34
39
|
AudioServicesRemoveSystemSoundCompletion(SystemSoundID(soundID))
|
35
|
-
AudioServicesDisposeSystemSoundID(SystemSoundID(soundID))
|
40
|
+
//AudioServicesDisposeSystemSoundID(SystemSoundID(soundID))
|
36
|
-
// 停止させたらタップできるようにする
|
37
|
-
startBtn.isEnabled = true
|
38
41
|
}
|
39
|
-
|
40
|
-
|
41
42
|
}
|
42
43
|
```
|
5
訂正
answer
CHANGED
@@ -3,4 +3,40 @@
|
|
3
3
|
|
4
4
|

|
5
5
|
|
6
|
-
で、原因はstartとstopの実装の仕方だと思います。startを2回タップするとおかしくなるので。
|
6
|
+
で、原因はstartとstopの実装の仕方だと思います。startを2回タップするとおかしくなるので。
|
7
|
+
適当でおすすめしませんが↓で回避はできますね。
|
8
|
+
MediaPlayerのループの制御の仕方を調べたほうが後々のたになると思います。
|
9
|
+
|
10
|
+
|
11
|
+
```swuft
|
12
|
+
|
13
|
+
class SoundViewController: UIViewController {
|
14
|
+
// アウトレットをつないで
|
15
|
+
@IBOutlet weak var startBtn: UIButton!
|
16
|
+
|
17
|
+
var soundID: Int = 1000
|
18
|
+
|
19
|
+
@IBAction func startBtnDidTap() {
|
20
|
+
let systemSoundID = SystemSoundID(soundID)
|
21
|
+
AudioServicesAddSystemSoundCompletion(systemSoundID, nil, nil, { (systemSoundID, nil) -> Void in
|
22
|
+
AudioServicesPlaySystemSound(systemSoundID)
|
23
|
+
}, nil)
|
24
|
+
AudioServicesPlaySystemSound(systemSoundID)
|
25
|
+
// 再生中はタップできなくする
|
26
|
+
startBtn.isEnabled = false
|
27
|
+
}
|
28
|
+
|
29
|
+
@IBAction func stopBtnDidTap() {
|
30
|
+
stopSystemSound()
|
31
|
+
}
|
32
|
+
|
33
|
+
func stopSystemSound() {
|
34
|
+
AudioServicesRemoveSystemSoundCompletion(SystemSoundID(soundID))
|
35
|
+
AudioServicesDisposeSystemSoundID(SystemSoundID(soundID))
|
36
|
+
// 停止させたらタップできるようにする
|
37
|
+
startBtn.isEnabled = true
|
38
|
+
}
|
39
|
+
|
40
|
+
|
41
|
+
}
|
42
|
+
```
|
4
訂正
answer
CHANGED
@@ -1,4 +1,6 @@
|
|
1
1
|
音はなりますね。
|
2
2
|
私なりに解釈すると[こうなりますが](https://github.com/tyobigoro/tPresent)、メモリの限界に挑戦するものを作りたくはありませんね。これでいいのでしょうか?
|
3
3
|
|
4
|
-

|
4
|
+

|
5
|
+
|
6
|
+
で、原因はstartとstopの実装の仕方だと思います。startを2回タップするとおかしくなるので。
|
3
訂正
answer
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
+
音はなりますね。
|
1
|
-
https://
|
2
|
+
私なりに解釈すると[こうなりますが](https://github.com/tyobigoro/tPresent)、メモリの限界に挑戦するものを作りたくはありませんね。これでいいのでしょうか?
|
2
3
|
|
3
|
-
同時に一個しか再生できないって。
|
4
|
-
|
4
|
+

|
2
訂正
answer
CHANGED
@@ -1,4 +1,4 @@
|
|
1
1
|
https://developer.apple.com/documentation/audiotoolbox/system_sound_services#//apple_ref/doc/uid/TP40007916
|
2
2
|
|
3
3
|
同時に一個しか再生できないって。
|
4
|
-
で、
|
4
|
+
で、遷移で永遠に進んでるからじゃないの?
|
1
訂正
answer
CHANGED
@@ -1,12 +1,4 @@
|
|
1
|
-
|
1
|
+
https://developer.apple.com/documentation/audiotoolbox/system_sound_services#//apple_ref/doc/uid/TP40007916
|
2
|
-
SoundViewControllerに↓でも貼って消えてることを確認してください。
|
3
2
|
|
4
|
-
```swift
|
5
|
-
override func viewDidDisappear(_ animated: Bool) {
|
6
|
-
super.viewDidDisappear(animated)
|
7
|
-
print("消えました")
|
8
|
-
}
|
9
|
-
```
|
10
|
-
|
11
|
-
|
3
|
+
同時に一個しか再生できないって。
|
12
|
-
|
4
|
+
で、繊維で永遠に進んでるからじゃないの?
|