Skip to content

Commit 4b4de9e

Browse files
committed
Stop audio when deleting memo that is playing (#214)
* wip * wip
1 parent 8337e8d commit 4b4de9e

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

Examples/VoiceMemos/VoiceMemos/VoiceMemo.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ let voiceMemoReducer = Reducer<VoiceMemo, VoiceMemoAction, VoiceMemoEnvironment>
5151

5252
case .delete:
5353
return .merge(
54+
environment.audioPlayerClient
55+
.stop(PlayerId())
56+
.fireAndForget(),
5457
Effect.cancel(id: PlayerId()),
5558
Effect.cancel(id: TimerId())
5659
)

Examples/VoiceMemos/VoiceMemosTests/VoiceMemosTests.swift

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,8 @@ class VoiceMemosTests: XCTestCase {
261261
}
262262

263263
func testDeleteMemo() {
264+
var didStopAudioPlayerClient = false
265+
264266
let store = TestStore(
265267
initialState: VoiceMemosState(
266268
voiceMemos: [
@@ -275,13 +277,17 @@ class VoiceMemosTests: XCTestCase {
275277
),
276278
reducer: voiceMemosReducer,
277279
environment: .mock(
280+
audioPlayerClient: .mock(
281+
stop: { _ in .fireAndForget { didStopAudioPlayerClient = true } }
282+
),
278283
mainQueue: self.scheduler
279284
)
280285
)
281286

282287
store.assert(
283288
.send(.voiceMemo(index: 0, action: .delete)) {
284289
$0.voiceMemos = []
290+
XCTAssertEqual(didStopAudioPlayerClient, true)
285291
}
286292
)
287293
}
@@ -302,7 +308,8 @@ class VoiceMemosTests: XCTestCase {
302308
reducer: voiceMemosReducer,
303309
environment: .mock(
304310
audioPlayerClient: .mock(
305-
play: { id, url in .future { _ in } }
311+
play: { id, url in .future { _ in } },
312+
stop: { _ in .fireAndForget { } }
306313
),
307314
mainQueue: self.scheduler
308315
)

0 commit comments

Comments
 (0)