Skip to content

Commit 78e7dca

Browse files
committed
fix: update media player source before playback status
1 parent 87db46d commit 78e7dca

File tree

2 files changed

+31
-6
lines changed

2 files changed

+31
-6
lines changed

src/resolvers/__tests__/media.spec.ts

+25
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import * as media from '../media'
22
import { Commands, Enums, MediaState, AtemStateUtil } from 'atem-connection'
3+
import { jsonClone } from '../../util'
34

45
const STATE1 = AtemStateUtil.Create()
56
;(STATE1.media.players as MediaState.MediaPlayerState[]) = [
@@ -68,3 +69,27 @@ test('Unit: media player: status command', function () {
6869
atBeginning: true,
6970
})
7071
})
72+
73+
test('Unit: media player: select clip and play', function () {
74+
const state1b = jsonClone(STATE1)
75+
if (state1b.media.players[0]) {
76+
state1b.media.players[0].clipIndex = 1
77+
state1b.media.players[0].playing = true
78+
state1b.media.players[0].loop = true
79+
}
80+
81+
const commands = media.resolveMediaPlayerState(STATE1, state1b) as Array<Commands.MediaPlayerStatusCommand>
82+
83+
expect(commands[0].constructor.name).toEqual('MediaPlayerSourceCommand')
84+
expect(commands[0].mediaPlayerId).toEqual(0)
85+
expect(commands[0].properties).toEqual({
86+
clipIndex: 1,
87+
})
88+
89+
expect(commands[1].constructor.name).toEqual('MediaPlayerStatusCommand')
90+
expect(commands[1].mediaPlayerId).toEqual(0)
91+
expect(commands[1].properties).toEqual({
92+
playing: true,
93+
loop: true,
94+
})
95+
})

src/resolvers/media.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,17 @@ export function resolveMediaPlayerState(
1414
const newPlayer = fillDefaults(Defaults.Video.MediaPlayer, newState.media?.players?.[index])
1515
const oldPlayer = fillDefaults(Defaults.Video.MediaPlayer, oldState.media?.players?.[index])
1616

17-
const props = diffObject<MediaState.MediaPlayer>(oldPlayer, newPlayer)
18-
const command = new AtemCommands.MediaPlayerStatusCommand(index)
19-
if (command.updateProps(props)) {
20-
commands.push(command)
21-
}
22-
2317
const srcProps = diffObject<MediaState.MediaPlayerSource>(oldPlayer, newPlayer)
2418
const srcCommand = new AtemCommands.MediaPlayerSourceCommand(index)
2519
if (srcCommand.updateProps(srcProps)) {
2620
commands.push(srcCommand)
2721
}
22+
23+
const props = diffObject<MediaState.MediaPlayer>(oldPlayer, newPlayer)
24+
const command = new AtemCommands.MediaPlayerStatusCommand(index)
25+
if (command.updateProps(props)) {
26+
commands.push(command)
27+
}
2828
}
2929

3030
return commands

0 commit comments

Comments
 (0)