Skip to content

Commit e0d6b68

Browse files
author
TinaTiel
committed
Added test for media capabilities, note there is an active bug on the toggle play/pause feature in Palakis' libarary
1 parent df207c7 commit e0d6b68

File tree

1 file changed

+71
-36
lines changed

1 file changed

+71
-36
lines changed

src/integrationTest/java/net/twasi/obsremotejava/test/ObsRemoteE2eObservationIT.java

Lines changed: 71 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,10 @@
44
import static org.junit.jupiter.api.Assertions.fail;
55

66
import java.io.File;
7-
import java.nio.file.Path;
8-
import java.nio.file.Paths;
97
import java.util.HashMap;
10-
import java.util.List;
118
import java.util.Map;
129
import java.util.function.Consumer;
1310
import net.twasi.obsremotejava.OBSRemoteController;
14-
import net.twasi.obsremotejava.objects.Scene;
1511
import org.junit.jupiter.api.AfterAll;
1612
import org.junit.jupiter.api.AfterEach;
1713
import org.junit.jupiter.api.BeforeAll;
@@ -26,6 +22,16 @@ public class ObsRemoteE2eObservationIT {
2622

2723
static OBSRemoteController remote;
2824

25+
private final String SOURCE_MEDIA = "media";
26+
private final String SOURCE_VLC_MEDIA = "vlc-media";
27+
private final String SOURCE_RED_SQUARE = "red_square";
28+
private final String SOURCE_RED_SQUARE_FILTER = "Color Correction";
29+
private final String SCENE1 = "scene1";
30+
private final String SCENE2 = "scene2";
31+
private final String TRANSITION_SLIDE = "Slide";
32+
private final String TRANSITION_CUT = "Cut";
33+
private final String TRANSITION_FADE = "Fade";
34+
2935
@BeforeAll
3036
static void beforeAll() {
3137

@@ -73,55 +79,57 @@ public void afterEach() {
7379
@Test
7480
void switchScene() {
7581
obsShould("Switch to scene2");
76-
remote.changeSceneWithTransition("scene2", "Cut", loggingConsumer);
82+
remote.changeSceneWithTransition(SCENE2, TRANSITION_CUT, loggingCallback);
7783
}
7884

7985
@Test
8086
void showHideSceneItem() {
8187
obsShould("Show the red square");
82-
remote.setSourceVisibility(null, "red_square", true, loggingConsumer);
88+
remote.setSourceVisibility(null, SOURCE_RED_SQUARE, true, loggingCallback);
8389
obsShould("Hide the red square");
84-
remote.setSourceVisibility(null, "red_square", false, loggingConsumer);
90+
remote.setSourceVisibility(null, SOURCE_RED_SQUARE, false, loggingCallback);
8591
}
8692

8793
@Test
8894
void setTransition() {
8995
obsShould("Set current transition to Slide, with transition 2000ms");
90-
remote.setCurrentTransition("Slide", loggingConsumer);
91-
remote.setTransitionDuration(2000, loggingConsumer);
96+
remote.setCurrentTransition(TRANSITION_SLIDE, loggingCallback);
97+
remote.setTransitionDuration(2000, loggingCallback);
9298
obsShould("Set current transition back to 300ms");
93-
remote.setTransitionDuration(300, loggingConsumer);
99+
remote.setTransitionDuration(300, loggingCallback);
94100
obsShould("Set current transition back to Cut");
95-
remote.setCurrentTransition("Cut", loggingConsumer);
101+
remote.setCurrentTransition(TRANSITION_CUT, loggingCallback);
96102
}
97103

98104
@Test
99105
void changeScenesWithTransition() {
100106
obsShould("Change to scene2, with the Slide transition");
101-
remote.changeSceneWithTransition("scene2", "Slide", loggingConsumer);
107+
remote.changeSceneWithTransition(SCENE2, TRANSITION_SLIDE, loggingCallback);
102108
}
103109

104110
@Test
105111
void setSourceFilterVisibility() {
106112

107113
obsShould("Show a blue square (red square colored blue by a filter)");
108-
remote.setSourceVisibility(null, "red_square", true, loggingConsumer);
109-
remote.setSourceFilterVisibility("red_square", "Color Correction", true, loggingConsumer);
114+
remote.setSourceVisibility(null, SOURCE_RED_SQUARE, true, loggingCallback);
115+
remote.setSourceFilterVisibility(SOURCE_RED_SQUARE, SOURCE_RED_SQUARE_FILTER, true,
116+
loggingCallback);
110117
obsShould("Return the red square to normal");
111-
remote.setSourceFilterVisibility("red_square", "Color Correction", false, loggingConsumer);
118+
remote.setSourceFilterVisibility(SOURCE_RED_SQUARE, SOURCE_RED_SQUARE_FILTER, false,
119+
loggingCallback);
112120

113121
}
114122

115123
@Test
116124
void exerciseStudioMode() {
117125
obsShould("Enable studio mode");
118-
remote.setStudioModeEnabled(true, loggingConsumer);
126+
remote.setStudioModeEnabled(true, loggingCallback);
119127
obsShould("Set preview scene to scene2");
120-
remote.setPreviewScene("scene2", loggingConsumer);
128+
remote.setPreviewScene(SCENE2, loggingCallback);
121129
obsShould("Fade to scene2");
122-
remote.transitionToProgram("Fade", 1500, loggingConsumer);
130+
remote.transitionToProgram(TRANSITION_FADE, 1500, loggingCallback);
123131
obsShould("Disable studio mode");
124-
remote.setStudioModeEnabled(false, loggingConsumer);
132+
remote.setStudioModeEnabled(false, loggingCallback);
125133

126134
}
127135

@@ -130,10 +138,10 @@ void setSourceSettings() {
130138
obsShould("Curse the 'scene1' text");
131139
Map<String, Object> settings = new HashMap<>();
132140
settings.put("text", "S̼͚̞̼̩̱̽̓̍̽͊́ͨ̍̀ċͭ̚҉̪̖̤̥ͅȩ͉̣̜̖̖͙͇́̀̒ͥ̓̚͠͞n̦͍͆͑ͤ̕e̶̖̝̗̻͂̑̽̔ͩ̅́͜ͅ ̢͉̬͔͙̺̖͂͂ͣ͢1̮̥͇̏̇͋̈́ͨͥ͝ͅ");
133-
remote.setSourceSettings("scenename1", settings, loggingConsumer);
141+
remote.setSourceSettings(SCENE1, settings, loggingCallback);
134142
obsShould("Change the 'scene1' text back to normal");
135143
settings.put("text", "Scene 1");
136-
remote.setSourceSettings("scenename1", settings, loggingConsumer);
144+
remote.setSourceSettings(SCENE1, settings, loggingCallback);
137145
}
138146

139147
@Test
@@ -144,52 +152,79 @@ void takeSourceScreenshot() throws Exception {
144152
String screenshotPath = file.getAbsolutePath();
145153
obsShould("Take a screenshot of the current scene, and save it to " + screenshotPath, 1);
146154
remote.takeSourceScreenshot(
147-
"scene1", "png",
155+
SCENE1, "png",
148156
screenshotPath,
149157
null, 1,
150158
1080, 720,
151-
loggingConsumer
159+
loggingCallback
152160
);
153161
}
154162

155163
@Test
156164
void startStopStreaming() {
157165
obsShould("Start Streaming");
158-
remote.startStreaming(loggingConsumer);
166+
remote.startStreaming(loggingCallback);
159167
obsShould("Stop Streaming");
160-
remote.stopStreaming(loggingConsumer);
168+
remote.stopStreaming(loggingCallback);
161169
}
162170

163171
@Test
164172
void startStopRecordingAndReplayBuffer() {
165173
obsShould("Start Recording");
166-
remote.startRecording(loggingConsumer);
174+
remote.startRecording(loggingCallback);
167175

168176
obsShould("Start the replay buffer");
169-
remote.startReplayBuffer(loggingConsumer);
177+
remote.startReplayBuffer(loggingCallback);
170178

171179
obsShould("Save the replay buffer");
172-
remote.saveReplayBuffer(loggingConsumer);
180+
remote.saveReplayBuffer(loggingCallback);
173181

174182
obsShould("Stop the replay buffer");
175-
remote.stopReplayBuffer(loggingConsumer);
183+
remote.stopReplayBuffer(loggingCallback);
176184

177185
obsShould("Stop Recording");
178-
remote.stopRecording(loggingConsumer);
186+
remote.stopRecording(loggingCallback);
179187
}
180188

181189
@Test
182190
void setVolumeAndMute() {
183191

184192
obsShould("Set the volume to 50% (note, appears 67% due to log scaling; check % in advanced audio properties)");
185-
remote.setSourceVisibility(null, "media", true, loggingConsumer);
186-
remote.setVolume("media", 0.50, loggingConsumer);
193+
remote.setSourceVisibility(null, "media", true, loggingCallback);
194+
remote.setVolume(SOURCE_MEDIA, 0.50, loggingCallback);
187195
obsShould("Mute the volume");
188-
remote.setMute("media", true, loggingConsumer);
196+
remote.setMute(SOURCE_MEDIA, true, loggingCallback);
189197
obsShould("Unmute the volume");
190-
remote.setMute("media", false, loggingConsumer);
198+
remote.setMute(SOURCE_MEDIA, false, loggingCallback);
191199
obsShould("Set the volume to 100%");
192-
remote.setVolume("media", 1.00, loggingConsumer);
200+
remote.setVolume(SOURCE_MEDIA, 1.00, loggingCallback);
201+
202+
}
203+
204+
@Test
205+
void playPauseVlcMedia() {
206+
obsShould("Play video 1, by showing it (Note, VLC must be installed!)");
207+
remote.setSourceVisibility(null, SOURCE_VLC_MEDIA, true, loggingCallback);
208+
209+
obsShould("Pause video 1");
210+
remote.pauseMedia(SOURCE_VLC_MEDIA, loggingCallback);
211+
212+
// BUG: Toggle Play/Pause does not work in Palakis OBS plugin!
213+
// see https://github.com/Palakis/obs-websocket/issues/725
214+
// I've noted we can also replicate the problem
215+
obsShould("Toggle Play Video 1");
216+
remote.toggleMedia(SOURCE_VLC_MEDIA, loggingCallback);
217+
obsShould("Toggle Pause Video 1");
218+
remote.toggleMedia(SOURCE_VLC_MEDIA, loggingCallback);
219+
220+
obsShould("Switch to video 2");
221+
remote.nextMedia(SOURCE_VLC_MEDIA, loggingCallback);
222+
223+
obsShould("Restart, back at video 1 (should auto play)");
224+
remote.restartMedia(SOURCE_VLC_MEDIA, loggingCallback);
225+
226+
obsShould("Stop video 1 (going back to beginning)");
227+
remote.stopMedia(SOURCE_VLC_MEDIA, loggingCallback);
193228

194229
}
195230

@@ -244,7 +279,7 @@ private void cleanupScenes() {
244279
});
245280
}
246281

247-
Consumer loggingConsumer = (obj) -> {
282+
Consumer loggingCallback = (obj) -> {
248283
System.out.println("Received response: " + obj);
249284
};
250285

0 commit comments

Comments
 (0)