Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 18 additions & 8 deletions sound-wav.el
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,14 @@
(set-process-query-on-exit-flag sound-wav--powershell-process nil)
sound-wav--powershell-process))))))

(defun sound-wav--do-play-by-powershell-process (files)
(defun sound-wav--do-play-by-powershell-process (files &optional inturruptp)
(and sound-wav--powershell-process
(comint-send-string sound-wav--powershell-process
(concat (mapconcat
(lambda (file)
(format "(New-Object Media.SoundPlayer \"%s\").PlaySync()"
(format (if inturruptp
"(New-Object Media.SoundPlayer \"%s\").Play()"
"(New-Object Media.SoundPlayer \"%s\").PlaySync()")
(cond
((memq system-type '(cygwin))
(cygwin-convert-file-name-to-windows file))
Expand All @@ -75,14 +77,16 @@
(and (executable-find "powershell")
(memq system-type '(windows-nt ms-dos cygwin))))

(defun sound-wav--do-play-by-powershell (files)
(defun sound-wav--do-play-by-powershell (files &optional inturruptp)
(deferred:$
(deferred:process
"powershell"
"-c"
(mapconcat
(lambda (file)
(format "(New-Object Media.SoundPlayer \"%s\").PlaySync()"
(format (if inturruptp
"(New-Object Media.SoundPlayer \"%s\").Play()"
"(New-Object Media.SoundPlayer \"%s\").PlaySync()")
file))
files
";"))))
Expand Down Expand Up @@ -114,11 +118,11 @@
(deferred:$
(apply 'deferred:process "aplay" files)))

(defun sound-wav--do-play (files)
(defun sound-wav--do-play (files &optional inturruptp)
(cond ((sound-wav--powershell-sound-player-process-p)
(sound-wav--do-play-by-powershell-process files))
(sound-wav--do-play-by-powershell-process files inturruptp))
((sound-wav--powershell-sound-player-p)
(sound-wav--do-play-by-powershell files))
(sound-wav--do-play-by-powershell files inturruptp))
((sound-wav--window-media-player-p)
(sound-wav--do-play-by-wmm files))
((executable-find "afplay")
Expand All @@ -140,6 +144,12 @@
(error "No valid files!!"))
(sound-wav--do-play valid-files)))

(provide 'sound-wav)
;;;###autoload
(cl-defun sound-wav-play-inturrupt (&rest files)
(let ((valid-files (sound-wav--validate-files files)))
(when (null files)
(error "No valid files!!"))
(sound-wav--do-play valid-files t)))

(provide 'sound-wav)
;;; sound-wav.el ends here