2020-09-25 22:38:08 +00:00
|
|
|
extends Control
|
|
|
|
|
|
|
|
var players = []
|
|
|
|
|
|
|
|
# Declare member variables here. Examples:
|
|
|
|
# var a = 2
|
|
|
|
# var b = "text"
|
|
|
|
var AudioSyncs = []
|
|
|
|
var AudioStreams = []
|
|
|
|
var AudioVolumes = []
|
2020-09-26 12:59:15 +00:00
|
|
|
var playing = false
|
2020-09-25 22:38:08 +00:00
|
|
|
export(VideoStreamWebm) var VideoStream
|
|
|
|
export(bool) var paused
|
|
|
|
export(int) var VideoDurationSeconds
|
|
|
|
export(float) var stream_position
|
|
|
|
export(float) var volume_db
|
|
|
|
signal finished
|
|
|
|
|
|
|
|
# Called when the node enters the scene tree for the first time.
|
|
|
|
func _ready():
|
|
|
|
$VideoPlayer.stream = VideoStream
|
|
|
|
$VideoPlayer.paused = paused
|
|
|
|
$TextureProgress.max_value = VideoDurationSeconds
|
|
|
|
$VideoPlayer.volume_db = volume_db
|
|
|
|
print(">>>count is "+String(len(AudioSyncs))+","+String(len(players))+","+String(len(AudioStreams)))
|
|
|
|
|
|
|
|
func play():
|
|
|
|
$VideoPlayer.play()
|
2020-09-26 12:59:15 +00:00
|
|
|
playing = true
|
2020-09-25 22:38:08 +00:00
|
|
|
|
|
|
|
func stop():
|
|
|
|
$VideoPlayer.stop()
|
|
|
|
for playerid in range(0,len(players)):
|
|
|
|
print(">>>Stopping player"+String(playerid))
|
|
|
|
players[playerid].stop()
|
2020-09-26 12:59:15 +00:00
|
|
|
playing = false
|
2020-09-25 22:38:08 +00:00
|
|
|
|
|
|
|
func set_VideoStream(new_stream):
|
|
|
|
VideoStream = new_stream
|
|
|
|
if !is_inside_tree(): return
|
|
|
|
$VideoPlayer.stream = new_stream
|
|
|
|
print(">>>VideoStream is now "+new_stream.to_string())
|
|
|
|
|
|
|
|
func set_paused(value):
|
|
|
|
if !is_inside_tree(): return
|
|
|
|
$VideoPlayer.paused = value
|
|
|
|
paused = value
|
|
|
|
print(">>>Paused is now "+String(value))
|
|
|
|
|
|
|
|
func set_VideoDurationSeconds(value):
|
|
|
|
if !is_inside_tree(): return
|
|
|
|
$TextureProgress.max_value = value
|
|
|
|
VideoDurationSeconds = value
|
|
|
|
print(">>>VideoDurationSeconds is now "+String(value))
|
|
|
|
|
|
|
|
func set_volume_db(value):
|
|
|
|
if !is_inside_tree(): return
|
|
|
|
$VideoPlayer.volume_db = value
|
|
|
|
volume_db = value
|
|
|
|
print(">>>volume_db is now "+String(value))
|
|
|
|
|
|
|
|
func set_audio_volume_db(which, value):
|
|
|
|
players[which].set_volume_db(value)
|
|
|
|
|
2020-09-26 12:59:15 +00:00
|
|
|
func set_stream_delay(which, value):
|
|
|
|
if playing:
|
|
|
|
if !paused:
|
|
|
|
$VideoPlayer.paused = true
|
|
|
|
for playerid in range(0,len(players)):
|
|
|
|
players[playerid].stream_paused = true
|
|
|
|
players[which].seek($VideoPlayer.stream_position + value)
|
|
|
|
if !paused:
|
|
|
|
$VideoPlayer.paused = false
|
|
|
|
for playerid in range(0,len(players)):
|
|
|
|
players[playerid].stream_paused = false
|
|
|
|
AudioSyncs[which] = value
|
|
|
|
|
2020-09-25 22:38:08 +00:00
|
|
|
func get_stream_position():
|
|
|
|
return $VideoPlayer.stream_position
|
|
|
|
|
|
|
|
func add_audio_stream(stream, delay):
|
|
|
|
var player = AudioStreamPlayer.new()
|
|
|
|
player.set_stream(stream)
|
|
|
|
player.volume_db = 1
|
|
|
|
player.pitch_scale = 1
|
|
|
|
add_child(player)
|
|
|
|
players.append(player)
|
|
|
|
AudioSyncs.append(delay)
|
|
|
|
AudioStreams.append(stream)
|
|
|
|
print(">>>added stream, count is now "+String(len(AudioSyncs))+","+String(len(players))+","+String(len(AudioStreams)))
|
|
|
|
|
|
|
|
func play_combined():
|
2020-09-26 12:59:15 +00:00
|
|
|
playing = true
|
2020-09-25 22:38:08 +00:00
|
|
|
$VideoPlayer.play()
|
|
|
|
for playerid in range(0,len(players)):
|
|
|
|
print(">>>Playing player"+String(playerid))
|
|
|
|
players[playerid].play()
|
|
|
|
players[playerid].stream_paused = true
|
|
|
|
players[playerid].seek(AudioSyncs[playerid])
|
|
|
|
players[playerid].stream_paused = false
|
|
|
|
|
|
|
|
|
|
|
|
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
|
|
|
func _process(delta):
|
|
|
|
$TextureProgress.value = $VideoPlayer.stream_position
|
|
|
|
|
|
|
|
|
|
|
|
func _on_VideoPlayer_finished():
|
2020-09-26 12:59:15 +00:00
|
|
|
playing = false
|
|
|
|
for playerid in range(0,len(players)):
|
|
|
|
print(">>>Stopping player"+String(playerid))
|
|
|
|
players[playerid].stop()
|
2020-09-25 22:38:08 +00:00
|
|
|
emit_signal("finished")
|