logo

Live Production Software Forums


Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

Options
Go to last post Go to first unread
john30120  
#1 Posted : Thursday, March 28, 2024 12:04:19 AM(UTC)
john30120

Rank: Member

Groups: Registered
Joined: 8/8/2019(UTC)
Posts: 24
United States
Location: Georgia

Was thanked: 2 time(s) in 2 post(s)
I have an MP3 music file (MyMusic.mp3) loaded in an audio input (IntroMusic) controlled by scripting. I need to find the runtime of the file before it is played. It should be in a Xaml read but I can't sort out the code to extract it.

Thanks in advance
Roy Sinclair  
#2 Posted : Thursday, March 28, 2024 7:14:35 AM(UTC)
Roy Sinclair

Rank: Advanced Member

Groups: Registered
Joined: 11/23/2020(UTC)
Posts: 152
United States
Location: Wichita

Thanks: 9 times
Was thanked: 21 time(s) in 17 post(s)
This MP3 player script I wrote checks the length of the MP3 in it's "playing" loop. Note that the length is in milliseconds.

You really should ask questions like this in the "Scripting For Dummies" thread here, it's a great resource for finding scripts and learning how to make them work.


Code:

'Script to be triggered by a Keypadkey or X-Key to start playing an MP3 as background audio

'  When you add a new MP3 player, you need to add it's key to this array
Dim PlayerKeys() as String = {"86fecea6-0bec-43b2-8989-4c548973b94f","a8bac9b2-0898-46ad-87b8-ef668d1f3147","0b59d4f0-a95d-4bbf-b6f5-3259045d8955","32fbcbd5-a1ff-4222-ac16-319c88b1d596","da73d4fd-0713-482b-966a-bd871c89f7a7","5700a5c0-a78d-4e7a-8848-23f11f4bcd34","c31f2b8b-0768-4e76-a0ab-f6668f1078a0","4c20abe9-e44b-4caa-8ab6-918bdb4704b3","bef6d0f0-466b-4129-a168-f0cf8ac107a0","e9b292c9-aa6a-4fb2-81e1-8f699c130ab1","85939ecf-941a-4ab1-b205-77b8d716cf8a","c93de854-7bad-457e-9cbb-544aa4017a86","8007b0ad-6fcf-4c88-9421-3411a94dcf37","f5981acd-c41b-42f7-b44f-060bb8d7bce8"}

Dim vMixState as new system.xml.xmldocument
vMixState.LoadXML(API.XML)





Dim PlayerNumber as integer = 0						' This is the only line that needs to be changed to change the player number, note it's zero based here and one based in the names





Dim PlayerKey as string = PlayerKeys(PlayerNumber)	' Get the Key for our player from the XML
Dim PlayerTitle as string = vMixState.SelectSingleNode("//input[@key='" & PlayerKeys(PlayerNumber) & "']/@title").Value	' Get the Title for our Player

' ----------- Check to make sure no MP3 player is currently running before we start another one ----------------------
Dim PlayerIndex as integer
Dim OKToPlay = true
For PlayerIndex = 0 to PlayerKeys.Length - 1
	Dim state as string = vMixState.SelectSingleNode("//input[@key='" & PlayerKeys(PlayerIndex) & "']/@state").Value
	if state = "Running"
		console.writeline(vMixState.SelectSingleNode("//input[@key='" & PlayerKeys(PlayerIndex) & "']/@title").Value & " is currently running, " & PlayerTitle & " cannot be started")
		OKToPlay = false
	'Else
	'	console.writeline("Player number " & CStr(PlayerIndex + 1) & " is not running")
	end if
Next

If OKToPlay   '  I would have liked to just quit executing in the above For statement if another player is running but there's no Quit statement implementation here so we have to use a honking big IF instead to bypass the functional code
	'-------------- 
	Dim MP3Player as Object = Input.Find(PlayerTitle)   ' Should use the Key but it's BROKEN!!!!!  so we have to use the Title instead
	console.writeline(PlayerTitle & " is now starting " & PlayerKey)

	' Configure Input to match requirements in case this is a newly added MP3 player - only needed once but doesn't hurt to change again
	MP3Player.Function("AutoPauseOff")			' Don't pause if someone sets this as "live" and then switches away from it, shouldn't happen but let's be safe
	MP3Player.Function("AutoPlayOff")			' Likewise don't start playing it if someone switches it "live"
	MP3Player.Function("AutoRestartOff")		' And don't restart it automatically either -- essentially we turn off the automatic actions
	MP3Player.Function("LoopOff")				' We are setting these to only play once, may need another script for repeat plays
	MP3Player.Function("AudioBusOff","M")		' Audio doesn't go to the master bus, it will get fed to the master through the local sound board
	MP3Player.Function("AudioBusOn","A")		' Audio goes to BUS A which feeds to our local sound board

	 
	' Now to set the MP3 to play

	MP3Player.Function("Restart")		' Make sure we play from the start
	MP3Player.Function("AudioOn")		' Turn on audio for this input
	MP3Player.Function("Play")			' Start the MP3 playing (finally!)
	console.writeline ( PlayerTitle & " should be playing")

	Dim MP3IsPlaying as boolean = true
	Do While MP3IsPlaying				' Now we loop until the MP3 finishes playing
		sleep(1000)																											' Start the loop by waiting 1 seecond (1000 milliseconds)
		vMixState.loadxml( API.XML() )																						' Load that XML into a document tree 
		Dim Duration as string = vMixState.SelectSingleNode("//input[@key='" & PlayerKey & "']/@duration").Value				' Find the "Duration" of the MP3 (in milliseconds)
		Dim Position as string = vMixState.SelectSingleNode("//input[@key='" & PlayerKey & "']/@position").Value				' Find the current playing point of the MP3 (in millseconds)
		'console.writeline("Duration=" & Duration & "  Position=" & Position)
		If Duration = Position																								' If the position is the same as the duration then it's finished playing
			MP3IsPlaying = false																
		end if
	Loop

	console.writeline(PlayerTitle & " finished playing")
	MP3Player.Function("AudioOff")		' Done so turn off the audio for this input
	console.writeline("Audio reset after " & PlayerTitle & " finished, script terminating")
end if 
john30120  
#3 Posted : Friday, March 29, 2024 5:56:31 AM(UTC)
john30120

Rank: Member

Groups: Registered
Joined: 8/8/2019(UTC)
Posts: 24
United States
Location: Georgia

Was thanked: 2 time(s) in 2 post(s)
I stumbled on a solution that seems to work"

' Given an Audio Input loaded with an MP3 file titled IntroHymn
' iMusicPlayTime is the runtime in seconds

dim iMusicPlayTime as integer
dim xml as string=API.XML()
dim x as new system.xml.xmldocument
x.loadxml(xml)
iMusicPlayTime = CInt(x.SelectSingleNode("//input[@title='IntroHymn']/@duration").Value)\1000
Users browsing this topic
Guest
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.