Skip to content

How to query if the ATEM 'On Air' button is on or off state? #59

@Jibun-no-Kage

Description

@Jibun-no-Kage

How to query if the ATEM 'On Air' button is on or off state? Google A.I. referenced a 'streaming' object for the switcher object, but apparently that does not exist? So the below code is bogus? Wrong?

import time
import PyATEMMax

# Replace with your ATEM's IP address
ATEM_IP = "192.168.1.111"

def get_streaming_state():
    """
    Connects to the ATEM and prints the streaming state in a loop.
    """
    # Create the ATEMMax object
    switcher = PyATEMMax.ATEMMax()

    try:
        print(f"[{time.ctime()}] Connecting to ATEM switcher at {ATEM_IP}...")
        switcher.connect(ATEM_IP)

        # Wait for the connection to be established
        if not switcher.waitForConnection():
            print("Failed to connect to the ATEM switcher.")
            return

        print(f"[{time.ctime()}] Connection successful. Checking streaming state...")

        while True:
            # The 'streaming' object contains information about the stream
            streaming_state = switcher.streaming.state
            
            # The 'streaming.state' enum has several states:
            # 0: Off
            # 1: On Air
            # 2: Starting
            # 3: Stopping
            
            # Print the current state
            if streaming_state == 1:
                print(f"[{time.ctime()}] Streaming is ON AIR.")
            elif streaming_state == 2:
                print(f"[{time.ctime()}] Streaming is STARTING.")
            elif streaming_state == 3:
                print(f"[{time.ctime()}] Streaming is STOPPING.")
            else:
                print(f"[{time.ctime()}] Streaming is OFF.")

            # Process incoming packets to receive updates from the switcher
            switcher.loop()
            
            # Wait for 1 second before checking again
            time.sleep(1)

    except KeyboardInterrupt:
        print("\nExiting script.")
    finally:
        # Gracefully disconnect
        switcher.disconnect()
        print("Disconnected from ATEM switcher.")

if __name__ == "__main__":
    get_streaming_state()

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions