fordon_greeman / voidfiles

Branch: 2079ec5
Switch branches/tags
main
theidioticdev add emacs 2079ec5 23h ago
86 lines · 3.1 KB Raw Blame History
1 ;;; emms-player-vlc.el --- vlc support for EMMS -*- lexical-binding: t; -*-
2
3 ;; Copyright (C) 2008-2021 Free Software Foundation, Inc.
4
5 ;; Authors: Yoni Rabkin <yrk@gnu.org>
6
7 ;; This file is part of EMMS.
8
9 ;; EMMS is free software; you can redistribute it and/or
10 ;; modify it under the terms of the GNU General Public License
11 ;; as published by the Free Software Foundation; either version 3
12 ;; of the License, or (at your option) any later version.
13
14 ;; EMMS is distributed in the hope that it will be useful,
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 ;; GNU General Public License for more details.
18
19 ;; You should have received a copy of the GNU General Public License
20 ;; along with EMMS; if not, write to the Free Software Foundation,
21 ;; Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
22
23 ;;; Commentary:
24
25 ;;; Code:
26
27 (require 'emms-compat)
28 (require 'emms-player-simple)
29
30 ;; I use this macro, and later override some of the stuff it defines
31 ;; in order to accomodate VLC's particular idioms.
32 (define-emms-simple-player vlc '(file url)
33 (concat "\\`\\(http[s]?\\|mms\\)://\\|"
34 (apply #'emms-player-simple-regexp
35 emms-player-base-format-list))
36 "vlc" "--intf=rc")
37
38 (define-emms-simple-player vlc-playlist '(streamlist)
39 "\\`http[s]?://"
40 "vlc" "--intf=rc")
41
42 ;; (kludge) By default, VLC does not quit after finishing to play a
43 ;; track, so the player sentinel has no way of telling that the next
44 ;; track should be played. Therefore I redefine this low-level
45 ;; function and add a "quit" track which is invisible to Emms.
46 (advice-add 'emms-player-vlc-start :override #'emms--vlc-quit-after-finish)
47 (defun emms--vlc-quit-after-finish (track &rest _)
48 (let ((process (apply #'start-process
49 emms-player-simple-process-name
50 nil
51 emms-player-vlc-command-name
52 ;; splice in params here
53 (append emms-player-vlc-parameters
54 (list (emms-track-name track))
55 '("vlc://quit")))))
56 ;; Add a sentinel for signaling termination.
57 (set-process-sentinel process #'emms-player-simple-sentinel))
58 (emms-player-started emms-player-vlc))
59
60 (defun emms-player-vlc-pause ()
61 "Depends on vlc's rc mode."
62 (process-send-string
63 emms-player-simple-process-name "pause\n"))
64
65 (defun emms-player-vlc-seek (sec)
66 "Seek relative within a stream."
67 (when (not (= 0 sec))
68 (process-send-string
69 emms-player-simple-process-name
70 (if (< 0 sec) "fastforward\n" "rewind\n"))))
71
72 (defun emms-player-vlc-seek-to (sec)
73 "Seek to time SEC within the stream."
74 (process-send-string
75 emms-player-simple-process-name
76 (format "seek %d\n" sec)))
77
78 (emms-player-set emms-player-vlc 'pause 'emms-player-vlc-pause)
79 (emms-player-set emms-player-vlc 'resume nil) ; pause is also resume
80 (emms-player-set emms-player-vlc 'start 'emms-player-vlc-start)
81 (emms-player-set emms-player-vlc 'seek 'emms-player-vlc-seek)
82 (emms-player-set emms-player-vlc 'seek-to 'emms-player-vlc-seek-to)
83
84 (provide 'emms-player-vlc)
85
86 ;;; emms-player-vlc.el ends here