Airplay Video automation

Hi! I am trying to set up some tests on AppleTV and i figured the way to do them is by using airplay video. The issue here is i want the tests to be automatically executed and i don't seem to see any way to automatize airplay except for using applescript with quicktime player. I tried to write a script that could do that but i get the "wrong index" error. My code below:

to replaceFrontQTPlayerWithFile(aFile)
	
	tell application "QuickTime Player"
		activate
		
		try
			set frontDoc to front document
			close front document
		on error err number errNum
			if errNum is -1719 then
				-- There is no open document
			else if errNum is -10000 then
				-- Front doc exists, but does not really...
			else
				log err
			end if
		end try
		
		open aFile
		tell application "System Events" to tell process "QuickTime Player"
			tell window 1
				click button 4
				delay 1
				pick menu item "WRO-CT-IE-ATV-2" of menu 0 of button 4
			end tell
		end tell
		play front document
		
		-- Hide QTP
		#tell application "System Events"
		#	keystroke "h" using command down
		#end tell
		
	end tell
end replaceFrontQTPlayerWithFile


on run
	set unixFile to "/Users/aet/signals/roomba_sdr_vfr_no_audio.mov"
	set macFile to POSIX file unixFile
	set fileRef to (macFile as alias)
	my replaceFrontQTPlayerWithFile(fileRef)
end run

Here i have two questions:

  1. Is there any other way to do that (maybe some airplay API/command line tool that could help me)?
  2. If not is there a way to make my code work?

I am using macOS 12 device with tvOS 16 AppleTV