-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplay_sound_globally.py
39 lines (27 loc) · 1.01 KB
/
play_sound_globally.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# based on https://gist.github.com/Palakis/2b7a0e872c66d209050f6e01b60f1c94
import obspython as S
mediaSource = None # Null pointer
outputIndex = 63 # Last index
def play_sound():
mediaSource = S.obs_source_create_private(
"ffmpeg_source", "Global Media Source", None
)
s = S.obs_data_create()
S.obs_data_set_string(s, "local_file", script_path() + "alert.mp3")
S.obs_source_update(mediaSource, s)
S.obs_source_set_monitoring_type(
mediaSource, S.OBS_MONITORING_TYPE_MONITOR_AND_OUTPUT
)
S.obs_data_release(s)
S.obs_set_output_source(outputIndex, mediaSource)
return mediaSource
def obs_play_sound_release_source():
r = play_sound()
S.obs_source_release(r)
def on_event(event):
if event == S.OBS_FRONTEND_EVENT_SCENE_CHANGED:
obs_play_sound_release_source()
def script_load(settings):
S.obs_frontend_add_event_callback(on_event)
def script_unload():
S.obs_set_output_source(outputIndex, None)