
    SOg"                        S SK r \ R                  " \5      r " S S\5      rS rSS jrS rSS jr	SS jr
SS	 jrS S
KJr  \" 5       r\S:X  a  \rON\S:X  a"  \	rS SKr\R                   S    S:  a   S SKJr  O'O&\
r\S:w  a   S SKr\R,                  " SS5        S SKJr  C\S:X  a  S SKJr  \" \S   5        gg! \ a    \R)                  S5        SS jr N8f = f!   \R)                  S5        SS jr NV= f)    Nc                       \ rS rSrSrg)PlaysoundException    N)__name__
__module____qualname____firstlineno____static_attributes__r       N/Users/admin/workspace/ai/Jarvis/env/lib/python3.13/site-packages/playsound.pyr   r      s    r   r   c                 J    SSK nUR                  S   S:  a  [        U 5      $ U $ )zE
Support passing in a pathlib.Path-like object by converting to str.
r   N   )sysversion_infostr)pathr   s     r   _canonicalizePathr      s+     
a4y r   c                 \  ^^ S[        U 5      -   S-   n SSKJmJmJn  SSKJn  UR                  UR                  UR                  UR                  /TR                  R                  l        UR                  UR                  UR                  /TR                  R                  l        UU4S jn [         R#                  S5        U" SR%                  U 5      5        U" SR%                  X(       a  S	OS
5      5        [         R#                  S5         U" SR%                  U 5      5        g! [&         a'    [         R)                  SR%                  U 5      5         gf = f!  U" SR%                  U 5      5        f ! [&         a'    [         R)                  SR%                  U 5      5         f f = f= f)a  
Utilizes windll.winmm. Tested and known to work with MP3 and WAVE on
Windows 7 with Python 2.7. Probably works with more file formats.
Probably works on Windows XP thru Windows 10. Probably works with all
versions of Python.

Inspired by (but not copied from) Michael Gundlach <gundlach@gmail.com>'s mp3play:
https://github.com/michaelgundlach/mp3play

I never would have tried using windll.winmm without seeing his code.
"r   )create_unicode_bufferwindllwintypessleepc                    > SnT" U5      nSR                  U 5      n [        TR                  R                  XUS-
  S5      5      nU(       ak  T" U5      nTR                  R	                  X4US-
  5        S[        U5      -   S-   U -   S-   UR                  -   n[        R                  U5        [        U5      eUR                  $ )NiX      r   z
    Error z for command:
        z
    )
joinintwinmmmciSendStringWmciGetErrorStringWr   valueloggererrorr   )commandbufLenbuf	errorCodeerrorBufferexceptionMessager   r   s         r   
winCommand!_playsoundWin.<locals>.winCommand&   s    #F+((7#33G&1*aPQ	/7KLL++IFQJO .Y ? C- !-/6!7 (!)+6+<+<!= LL)*$%566yyr   Startingzopen {}z	play {}{}z wait 	Returningzclose {}zFailed to close the file: {}N)r   ctypesr   r   r   timer   LPCWSTRLPWSTRUINTHANDLEr!   r"   argtypesDWORDr#   r%   debugformatr   warning)soundblockr   r   r-   r   r   s        @@r   _playsoundWinr?      sM    #E**S0E>>,4,<,<hoox}}^f^m^m+nFLL(08QYQ^Q^/_FLL##,Z :$$U+,<&&ugBGH[!	{))%01! 	NN:AA%HI		{))%01! 	NN:AA%HI	sC   /A!E D) ).EEF+E76F+7.F(%F+'F((F+c                    [        U 5      n SU ;  a.  U R                  S5      (       d  SSKJn  U" 5       S-   U -   n SU -   n  U R	                  S5        U R                  SS5      $ ! [         af     SS	KJn  O! [         a	    SS	K
Jn   Of = fU R                  SS
5      nUS   S-   U" US
   R	                  S5      5      R                  SS5      -   s $ f = f)Nz:///r   )getcwdfile://asciir   z%20)quoter   zutf-8)r   
startswithosrB   encodereplaceUnicodeEncodeErrorurllib.parserE   ImportErrorurllibsplit)r=   rB   rE   partss       r   _handlePathOSXrP   B   s    e$EE$$!HsNU*EE!VW}}S%(( V	%* 	%$	% E1%Qx%%a(@"A"I"I#u"UUUVs7   "A$ $
C/A65C6B	CB		ACCc                 B    SSK Jn  SSKJ	n  SSK
Jn  [        U 5      n UR                  U 5      nU(       d  [        SU -   5      e[        S5       HE  nUR                   " 5       R#                  US	5      nU(       a    O*[        R%                  S
U -   5        MG     [        SU -   5      eUR'                  5         U(       a  U" UR)                  5       5        gg! [         a>    [        R	                  S5        [
        R                  R                  S5        SSK Jn   GNf = f)a  
Utilizes AppKit.NSSound. Tested and known to work with MP3 and WAVE on
OS X 10.11 with Python 2.7. Probably works with anything QuickTime supports.
Probably works on OS X 10.5 and newer. Probably works with all versions of
Python.

Inspired by (but not copied from) Aaron's Stack Overflow answer here:
http://stackoverflow.com/a/34568298/901641

I never would have tried using AppKit.NSSound without seeing his code.
r   NSSoundzVplaysound could not find a copy of AppKit - falling back to using macOS's system copy.zQ/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/PyObjC)NSURLr   #Cannot find a sound with filename:    Tz/Failed to load sound, although url was good... z=Could not load sound with filename, although URL was good... N)AppKitrS   rL   r%   r<   r   r   append
FoundationrT   r3   r   rP   URLWithString_r   rangealloc"initWithContentsOfURL_byReference_r:   playduration)r=   r>   rS   rT   r   urlinssounds           r   _playsoundOSXrc   Y   s    #" ! 5!E  'C !F!NOO1X--/DDS$OLLJURS  !!`ch!hiiLLNg ! /  #opkl""#s   C ADDc                    [        U 5      n SSKJnJn   SSKJn  SSKnUR                  " SS5        SSK
Jn  UR                  " S5        UR                  R                  SS5      nU R                  S	5      (       a  XR                   l        OIU" U 5      nU" U5      (       d  [%        S
R'                  U5      5      eSU" U5      -   UR                   l        UR)                  UR*                  R,                  5      n	XR.                  R0                  :w  a  [%        S[3        U	5      -   5      e[4        R7                  S5        U(       af  UR9                  5       n
 U
R;                  UR<                  R>                  UR@                  5        UR)                  UR*                  RB                  5        [4        R7                  S5        g! [         a
    SSKJn   GNf = f! UR)                  UR*                  RB                  5        f = f)zPlay a sound using GStreamer.

Inspired by this:
https://gstreamer.freedesktop.org/documentation/tutorials/playback/playbin-usage.html
r   abspathexists)pathname2urlNGst1.0ri   playbin)zhttp://zhttps://zFile not found: {}rC   zplaybin.set_state returned zStarting playzFinishing play)"r   os.pathrf   rg   urllib.requestrh   rL   rM   girequire_versiongi.repositoryri   initElementFactorymakerF   propsurir   r;   	set_stateStatePLAYINGStateChangeReturnASYNCreprr%   r:   get_buspollMessageTypeEOSCLOCK_TIME_NONENULL)r=   r>   rf   rg   rh   ro   ri   rl   r   
set_resultbuss              r   _playsoundNixr      s    e$E ((/
 ue$!HHTN  %%i;G/00!u~d||$%:%A%A$%GHH%T(:: ""399#4#45J**000 )D,<<> 	>
 LL!oo	.HHS__((#*=*=>ciinn-
LL!"G  (''(B ciinn-s   G 0G GG'Hc                 :  ^ ^^^
^ SSK Jn  SSKJnJn  SSKJm
  SSKJn  [        T5      m " S SU5      nU" U" T5      5      (       d  [        ST-   5      eU" U" S	 5      5      mU" U
UU UU4S
 jS9n	U	R                  5         U(       a  U	R                  5         gg)z
Mostly written so that when this is run on python3 on macOS, it can invoke
python2 on macOS... but maybe this idea could be useful on linux, too.
r   )getsourcefilere   )
check_call)Threadc                   2   ^  \ rS rSrS rSU 4S jjrSrU =r$ )2_playsoundAnotherPython.<locals>.PropogatingThread   c                     S U l          U R                  " U R                  0 U R                  D6U l        g ! [
         a  nXl          S nAg S nAff = fN)exc_target_args_kwargsretBaseException)selfes     r   run6_playsoundAnotherPython.<locals>.PropogatingThread.run   sB    DH<<Dt||D  s   +5 
AA

Ac                 t   > [         TU ]  U5        U R                  (       a  U R                  eU R                  $ r   )superr   r   r   )r   timeout	__class__s     r   r   7_playsoundAnotherPython.<locals>.PropogatingThread.join   s(    GL!xxhh88Or   )r   r   r   )r   r   r	   r
   r   r   r   __classcell__)r   s   @r   PropogatingThreadr      s    		 	r   r   rU   c                      g)Nr   r   r   r   r   <lambda>)_playsoundAnotherPython.<locals>.<lambda>   s    !r   c                  H   > T " TTT(       a  [        T5      /5      $ T/5      $ r   )rP   )r   macOSotherPythonplaysoundPathr=   s   r   r   r      s$    :{MlqSabgSh6}+~w|6}+~r   )targetN)inspectr   rm   rf   rg   
subprocessr   	threadingr   r   r   startr   )r   r=   r>   r   r   rf   rg   r   r   tr   r   s   `` `      @@r   _playsoundAnotherPythonr      s    
 )*%!e$EF  '%.!! !F!NOOM)45M#~#~AGGI	 r   )systemWindowsDarwin   rR   z~playsound is relying on a python 2 subprocess. Please use `pip3 install PyObjC` if you want playsound to run more efficiently.c                     [        SXSS9$ )NzC/System/Library/Frameworks/Python.framework/Versions/2.7/bin/pythonTr   r   r=   r>   s     r   r   r      s     4K  MR  TY  jn  5or   __main__ri   rj   rk   zplaysound is relying on another python subprocess. Please use `pip install pygobject` if you want playsound to run more efficiently.c                     [        SXSS9$ )Nz/usr/bin/python3Fr   r   r   s     r   r   r      s    4KL^`ev{4|r   )argvr   )T)TF)logging	getLoggerr   r%   	Exceptionr   r   r?   rP   rc   r   r   platformr   	playsoundr   r   rW   rS   rL   r<   ro   rp   rq   ri   r   r   r   r   <module>r      s*   			8	$	 	
-^V.&"P/#b"H 		YIxI
Q	o&  I:	}ue,)
 zd1g !  	oNN  \  ] oI	o	}NN  b  c|Is   2B: C :CCC6