asingcrow/godot/Components/MultiStreamPlayer.gd

114 lines
3.1 KiB
GDScript3
Raw Permalink Normal View History

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
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
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
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
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
$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()
emit_signal("finished")