#!/usr/bin/python3
import os,sys

write_path = "/userdata/ispeaker.fifo"

if __name__ == "__main__":
    if len(sys.argv) != 2 or (sys.argv[1] != "resume_music" and sys.argv[1] != "stop_music"):
        print("Usage:./ispeakerctl <action>")
        print("\tresume_music\tresume play music.")
        print("\tstop_music\tstop play music.")
        exit(0)


    wf = os.open(write_path, os.O_SYNC | os.O_CREAT | os.O_RDWR)

    action = sys.argv[1]

    if action == "stop_music":
        os.write(wf, "0".encode())
    elif action == "resume_music":
        os.write(wf, "1".encode())
    else:
        os.close(wf)
        exit(-1)

    os.close(wf)
    exit(0)