From mboxrd@z Thu Jan 1 00:00:00 1970 From: Michael Brand Subject: Re: Audio/video file playback in org mode Date: Fri, 10 Jun 2011 10:28:01 +0200 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Return-path: Received: from eggs.gnu.org ([140.186.70.92]:58877) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QUx4X-0004mq-Mq for emacs-orgmode@gnu.org; Fri, 10 Jun 2011 04:28:07 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1QUx4W-0003rf-9x for emacs-orgmode@gnu.org; Fri, 10 Jun 2011 04:28:05 -0400 Received: from mail-ew0-f41.google.com ([209.85.215.41]:63802) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QUx4V-0003rS-VJ for emacs-orgmode@gnu.org; Fri, 10 Jun 2011 04:28:04 -0400 Received: by ewy9 with SMTP id 9so956635ewy.0 for ; Fri, 10 Jun 2011 01:28:02 -0700 (PDT) In-Reply-To: List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: Paul Sexton Cc: emacs-orgmode@gnu.org Hi Paul Thank you very much for sharing this, I will benefit a lot and the interactivity from within Emacs seems extremely useful. My recent searches for how to play an Org link to an audio file didn't find any result and I was about to work out something with mpg123. I planned to define a new link type for this but your solution with "file:" looks to me more like it should be and is also backwards compatible with links already made with "file:". And even better if "file:" could also cover my requirement to have an optional link search part that lets the player start and stop at a specified time. Let me define the format like this: - start to play in file at 00:03:21, stop at 00:06:54: [[file:some_podcast.mp3::00:03:21-00:06:54]] - start to play in file at 00:03:21, play until end of file: [[file:some_podcast.mp3::00:03:21]] - play the whole file: [[file:some_podcast.mp3]] I would like to explicitly not allow [[file:some_podcast.mp3::03:21]] as a shorter option with MM:SS because I would like to see XX:XX being reserved for HH:MM without exception in Org. There was a recent discussion covering this in the context of time calculation: http://thread.gmane.org/gmane.emacs.orgmode/39487/focus=3D39840 Michael On Thu, Jun 9, 2011 at 23:55, Paul Sexton wrote: > I have spent a few hours figuring this out so I thought I would post it f= or > the benefit of others. > > I am learning a language, and wanted to include hyperlinks to audio files > within my org document, and be able to play each file by clicking on the > link. > > I eventually discovered the variable 'org-file-apps' which allows you to > associate particular applications with particular file types. > > I am using Bongo (https://github.com/dbrock/bongo) as the media player. > EMMS is another actively developed media player, but setup looked too > complicated at first glance. > > I am using MPlayer as the actual media player. This supports almost all > audio and video file formats. Most importantly, it works on Windows as we= ll > as on Linux (VLC has a Windows port but it doesn't work with Bongo as the > 'fake-tty' interface is not implemented on Windows.) > > My current setup means that clicking on a link such as [[file:song.mp3]] > adds it to the active Bongo playlist (in another buffer) and immediately > starts playing it. Playback can be paused, fast-forwarded etc using > Bongo. > > When Bongo plays a file it puts some icons in the modeline that > resemble the 'play', 'stop' etc symbols, and can be used to control > playback using the mouse. I found these worked erratically outside > the actual Bongo playlist buffer, so I have instead bound some > org-mode keys (ctrl + numpad keys) to the relevant functions. > This is optional of course. > > I have only tested this with mp3 files, but it ought to work with > video as well. > > > My setup follows: > ------------------- > > ;;; Part 1. Bongo setup > > (add-to-list 'load-path "/path/to/bongo")) > (autoload 'bongo "bongo" > =A0"Start Bongo by switching to a Bongo buffer." t) > > (setq bongo-mplayer-program-name > =A0 =A0 =A0(case system-type > =A0 =A0 =A0 =A0((windows-nt cygwin) "c:\\Program Files\\MPlayer for Windo= ws\\MPlayer.exe") > =A0 =A0 =A0 =A0(t "mplayer"))) > > (setq bongo-enabled-backends '(mplayer)) > > ;;; Part 2. Org setup > > (defvar av-file-regex > =A0(concat "\\." (regexp-opt > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 (append bongo-audio-file-name-extensions > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 bongo-video-file-name-ext= ensions)) "$")) > > (add-to-list 'org-file-apps > =A0 =A0 =A0 =A0 =A0 =A0 (cons av-file-regex '(org-play-media-file file))) > > (defun org-play-media-file (filename) > =A0(with-bongo-buffer > =A0 =A0(bongo-insert-file filename) > =A0 =A0(backward-char) > =A0 =A0(bongo-play))) > > ;;; Part 3. Keybindings to allow control of playback within Org buffer > ;;; (optional) > > ;; Numpad Ctrl-0: pause/resume > (define-key org-mode-map (kbd "") 'bongo-pause/resume) > (define-key org-mode-map (kbd "") 'bongo-pause/resume) > ;; Numpad Ctrl-.: stop current track, or restart from beginning if stoppe= d > (define-key org-mode-map (kbd "") 'bongo-start/stop) > (define-key org-mode-map (kbd "") 'bongo-start/stop) > ;; Numpad Ctrl-PgUp, Ctrl-PgDn: raise/lower volume > (define-key org-mode-map (kbd "") 'bongo-volume-raise) > (define-key org-mode-map (kbd "") 'bongo-volume-lower) > (define-key org-mode-map (kbd "") 'bongo-volume-raise) > (define-key org-mode-map (kbd "") 'bongo-volume-lower) > ;; Numpad Ctrl-left, Ctrl-right: skip back/forward 10 seconds > (define-key org-mode-map (kbd "") 'bongo-seek-backward-10) > (define-key org-mode-map (kbd "") 'bongo-seek-forward-10) > (define-key org-mode-map (kbd "") 'bongo-seek-backward-10) > (define-key org-mode-map (kbd "") 'bongo-seek-forward-10)