l3kn / org-fc

Spaced Repetition System for Emacs org-mode
https://www.leonrische.me/fc/index.html
GNU General Public License v3.0
258 stars 31 forks source link

Setting a position for an org-fc-audio card does not work #127

Open daraul opened 3 months ago

daraul commented 3 months ago

I've installed org-fc-audio, and can confirm that it works -- see my example card below.

* Just a test :fc:
:PROPERTIES:
:FC_CREATED: 2024-05-03T21:19:22Z
:FC_TYPE:  text-input
:FC_ALGO:  sm2
:ID:       c0a80c84-85bd-4028-b719-69b39be3d679
:FC_AUDIO_BEFORE_SETUP_FRONT: /Users/daraul/Test\ Method.mp3
:FC_AUDIO_AFTER_SETUP_FRONT: /Users/daraul/Test\ Method.mp3
:END:
:REVIEW_DATA:
| position | ease | box | interval | due                  |
|----------+------+-----+----------+----------------------|
| front    | 2.50 |   0 |     0.00 | 2024-05-03T21:19:22Z |
:END:
Foo

I was under the impression that I'd be able to set the position of the audio, but so far my attempts have silently failed:

:FC_AUDIO_BEFORE_SETUP_FRONT: /Users/daraul/Test\ Method.mp3#4:44
:FC_AUDIO_BEFORE_SETUP_FRONT: /Users/daraul/Test\ Method.mp3::4:44
:FC_AUDIO_BEFORE_SETUP_FRONT: /Users/daraul/Test\ Method.mp3:4:44:44

Am I making some syntax error, or is it not possible to start playback at a particular position?

l3kn commented 3 months ago

I've tried to implement this but couldn't find a way that's flexible and stable yet.

(defun org-fc-audio-play-file (file speed)
  "Play the audio FILE at SPEED."
  (org-fc-audio-stop)
  (setq org-fc-audio-last-file file)
  (let* ((tokens (split-string file " "))
         (path (car tokens))
         (range (when (eq (length tokens) 2)
                  (split-string (cadr tokens) "-")) )
         (command
          (if range
              (format
               "mpv %s --speed=%f --start=%s --end=%s"
               path speed (car range) (cadr range))
            (format "mpv %s --speed=%f" path speed))))

This approach will not work in your case because the filename you're using has a space in it and there's no end range.

We can try coming up with a better way of passing extra arguments that will ideally work for different playback programs.

One idea would be something like :FC_AUDIO_BEFORE_SETUP_FRONT: /Users/daraul/Test\ Method.mp3 :start 1:23 :end 4:56 where the space in the filename can be correctly parsed with a bit of effort.

daraul commented 3 months ago

I think passing extra arguments would be the better option. That way, you don't have to worry too much about spaces in the file path, and it'd be easier to discover this functionality by inspecting the package's arguments with describe-variable.