maemo.org - Talk

maemo.org - Talk (https://talk.maemo.org/index.php)
-   General (https://talk.maemo.org/forumdisplay.php?f=7)
-   -   aUDIOBOOK? (https://talk.maemo.org/showthread.php?t=19085)

MstPrgmr 2008-04-14 00:50

aUDIOBOOK?
 
What music player is best for audiobooks? The most important feature I am looking for is the ability to place bookmarks or have the app remember the last position of play. I have large audiobooks that are set up as a continuous audiobook so it is imperative that the player has some way to resume playback. I have heard of kabook for KDE, but I am looking for something that runs on the general OS.

JoeF 2008-04-14 01:04

Re: aUDIOBOOK?
 
I have been puzzling over this same question and have arrived at the conclusion that none of the media players for the Nokia nXX support audiobooks. None have a resume function or a bookmark function.

jldiaz 2008-04-14 07:13

Re: aUDIOBOOK?
 
Mplayer could be a candidate. It can play a wide range of audio formats, and in the latest version it is able to resume the last file played.

However, in order to be a good audiobook player some changes are needed:
  1. The GUI only shows videos. It does not show audio files (although it can play them if they are selected through the "Open" button)
  2. The resume capability is only present in the GUI (as far as I know), so it is limited to video files.
  3. The resume capability only remembers the resume point of the last file player. It would be very useful if it could remember a resume point for *each* file played. I don't think this is a technical limitation. The resume point is stored in the file ~/.mplayer/video.position and currenty only contains one line. It would be possible to include several lines here, one per file played.
  4. It does not provide bookmarking, but perhaps it would be not difficult to add it using the same mechanism than the one used for resuming.

However, it is also possible to use mplayer from command line, to play an audio file. The command-line version allows for the option -ss to start playing at any specified offset in the file (specified as seconds, or as HH:MM:SS). This would allow for a python script which manages the bookmarks and calls mplayer with the appropiate -ss options. Mplayer is continuosly printing the playing position in the standard output, so the python script could parse this information, in order to store the time offset at which mplayer is stopped, and save it as a resume point (to be used with option -ss in the next play).

MstPrgmr 2008-04-14 13:05

Re: aUDIOBOOK?
 
Quote:

Originally Posted by jldiaz (Post 169460)
Mplayer could be a candidate. It can play a wide range of audio formats, and in the latest version it is able to resume the last file played.

However, in order to be a good audiobook player some changes are needed:
  1. The GUI only shows videos. It does not show audio files (although it can play them if they are selected through the "Open" button)
  2. The resume capability is only present in the GUI (as far as I know), so it is limited to video files.
  3. The resume capability only remembers the resume point of the last file player. It would be very useful if it could remember a resume point for *each* file played. I don't think this is a technical limitation. The resume point is stored in the file ~/.mplayer/video.position and currenty only contains one line. It would be possible to include several lines here, one per file played.
  4. It does not provide bookmarking, but perhaps it would be not difficult to add it using the same mechanism than the one used for resuming.

However, it is also possible to use mplayer from command line, to play an audio file. The command-line version allows for the option -ss to start playing at any specified offset in the file (specified as seconds, or as HH:MM:SS). This would allow for a python script which manages the bookmarks and calls mplayer with the appropiate -ss options. Mplayer is continuosly printing the playing position in the standard output, so the python script could parse this information, in order to store the time offset at which mplayer is stopped, and save it as a resume point (to be used with option -ss in the next play).


Unfortunately, I have no maemo or python programming experience and am not able to implement those changes. Hopefully, someone will in the future.

JoeF 2008-04-14 14:05

Re: aUDIOBOOK?
 
I am not up to this task either. I am in the process (very slow) of cloning the OS so I can try GArnet VM and pocket tunes on a much larger partition. I will be able to load books onto the same partition as GVM and still have tons of room. I'll post my results.

Benson 2008-04-14 15:45

Re: aUDIOBOOK?
 
Why does everyone want to do everything with Python? :confused:
Shell scripts, awk, etc. are more than sufficient for this task. If you need limited graphical interaction with the user, gxmessage is in these forums.

What format are your audiobooks? mpg123 might seem a more natural choice than mplayer, if they're mp3; otherwise mplayer might be better.

jldiaz 2008-04-14 16:42

Re: aUDIOBOOK?
 
Quote:

Originally Posted by Benson (Post 169597)
Why does everyone want to do everything with Python? :confused:
Shell scripts, awk, etc. are more than sufficient for this task.

You are right. Using python for everything is a tic. I accomplished this task with a simple shell script and a little of awk. Here is how:

Copy the following code to a file named, for example abplayer (from "audiobook player), or wathever you like:

Code:

#!/bin/sh
if test -f "$1".resume
then
 resumepoint=`cat "$1".resume`
else
 resumepoint=0
fi
mplayer -ss $resumepoint "$1"|awk 'BEGIN{RS="\r"}{if ($1=="A:") t=$2}END{print t}' > "$1".resume

Put this file in a place where your shell can find it (I have a "bin" folder in my $HOME, and a line in the .profile for adding this folder to the PATH variable). Make executable this file (chmod +x abplayer).

Then, use it from the command line (xterm) like this:
Code:

$ abplayer /route/to/audiobook.mp3
The audio begins to play. When you press 'q', the player is exited, and a new file is created, with name /route/to/audiobook.mp3.resume which contains the time in which the playback was quitted. Next time you use abeplay, it will search for this file. If it founds it, the playback is resumed from that point. If not, it is restarted again from the beginning.

If the player exits unexpectedly and the .resume file is corrupt, you have to delete it (or you can write a correct one with any editor, it only contains the time where the playback has to be resumed, in the format hh:mm:ss.ff, being ff any fraction of second, for example: 3:21.52)

Quote:

Originally Posted by Benson (Post 169597)
What format are your audiobooks? mpg123 might seem a more natural choice than mplayer, if they're mp3; otherwise mplayer might be better.

I used mplayer because I have it already installed, and supports a wide range of formats. As for mpg123, I did not find it with apt-cache...

MstPrgmr 2008-04-14 18:09

Re: aUDIOBOOK?
 
Quote:

Originally Posted by jldiaz (Post 169625)
You are right. Using python for everything is a tic. I accomplished this task with a simple shell script and a little of awk. Here is how:

Copy the following code to a file named, for example abplayer (from "audiobook player), or wathever you like:

Code:

#!/bin/sh
if test -f "$1".resume
then
 resumepoint=`cat "$1".resume`
else
 resumepoint=0
fi
mplayer -ss $resumepoint "$1"|awk 'BEGIN{RS="\r"}{if ($1=="A:") t=$2}END{print t}' > "$1".resume

Put this file in a place where your shell can find it (I have a "bin" folder in my $HOME, and a line in the .profile for adding this folder to the PATH variable). Make executable this file (chmod +x abplayer).

Then, use it from the command line (xterm) like this:
Code:

$ abplayer /route/to/audiobook.mp3
The audio begins to play. When you press 'q', the player is exited, and a new file is created, with name /route/to/audiobook.mp3.resume which contains the time in which the playback was quitted. Next time you use abeplay, it will search for this file. If it founds it, the playback is resumed from that point. If not, it is restarted again from the beginning.

If the player exits unexpectedly and the .resume file is corrupt, you have to delete it (or you can write a correct one with any editor, it only contains the time where the playback has to be resumed, in the format hh:mm:ss.ff, being ff any fraction of second, for example: 3:21.52)



I used mplayer because I have it already installed, and supports a wide range of formats. As for mpg123, I did not find it with apt-cache...


Thanks, this looks good. However, when I tried this I keep getting
"sh: abplayer: Permission denied"

Benson 2008-04-14 18:18

Re: aUDIOBOOK?
 
chmod +x abplayer

MstPrgmr 2008-04-14 18:21

Re: aUDIOBOOK?
 
Quote:

Originally Posted by Benson (Post 169693)
chmod +x abplayer


I did that and it still says "/bin/sh: abplayer: not found"

Benson 2008-04-14 18:24

Re: aUDIOBOOK?
 
Is the location of abplayer on your PATH?

MstPrgmr 2008-04-14 18:28

Re: aUDIOBOOK?
 
Yes. I am in /media/mmc2. Here is the xterm

/media/mmc2 # chmod +x abplayer
/media/mmc2 # ./abplayer test.mp3
/bin/sh: ./abplayer: Permission denied
/media/mmc2 #

jldiaz 2008-04-14 18:39

Re: aUDIOBOOK?
 
Quote:

Originally Posted by MstPrgmr (Post 169696)
I did that and it still says "/bin/sh: abplayer: not found"

You need to specify the absolute or relative path to the executable. For example, assuming that you put the abplayer file in your home directory, in the xterm you type:

Code:

$ /home/user/abplayer /path/to/audiobook.mp3
Or, if you are at the same folder than the executable, you can use the simpler relative path: ./abplayer

Alternatively, you can put the executable at user scripts folder, named for example /home/user/bin, and add this folder to the PATH variable, by writting the following lines in your /home/user/.profile file:

Code:

PATH=$PATH:/home/user/bin
export PATH

This way, next time you open xterm, you can simply write "abplayer" without need to specify any path (and this will be also true for any future script you put in your bin folder).

jldiaz 2008-04-14 18:40

Re: aUDIOBOOK?
 
Quote:

Originally Posted by MstPrgmr (Post 169700)
Yes. I am in /media/mmc2.

Perhaps the filesystem in /media/mmc2 is mounted with execution forbidden. Try to put the script in the root filesystem.

Benson 2008-04-14 18:49

Re: aUDIOBOOK?
 
Correct; by default FAT systems are non-executable on the Nokias.

MstPrgmr 2008-04-14 18:49

Re: aUDIOBOOK?
 
Arrg. Now I moved the file to the /home directory and it says

/home # ./abplayer
/bin/sh: ./abplayer: Permission denied
/home # chmod +x abplayer
/home # ./abplayer /home/test.mp3
/bin/sh: ./home/abplayer: not found
/home # ./home/abplayer /home/test.mp3
/bin/sh: ./home/abplayer: not found

Benson 2008-04-14 21:20

Re: aUDIOBOOK?
 
Hmmm... I assume you have mplayer installed, and awk is installed by default.

It looks like you typed in the output? If the first line saying
Code:

/bin/sh: ./home/abplayer: not found
isn't a typo, then I have no clue how you're getting it.

MstPrgmr 2008-04-14 21:38

Re: aUDIOBOOK?
 
yea, i dunno. 1/2 the time i get permission denied. the other 1/2 i get abplayer not found. i am now strictly getting abplayer not found. i will reflash later and try again i guess

Benson 2008-04-14 21:43

Re: aUDIOBOOK?
 
Reflashing has nothing to do with this.

Do you in fact have mplayer installed?

MstPrgmr 2008-04-14 22:11

Re: aUDIOBOOK?
 
Yea, i have mplayer installed. I can execute the test.mp3 file I have by entering mplayer /(path to file)/test.mp3

I don't know if something happened to my N800 or what, but I have gotten different results from typing in the same exact commands. Either not found or permission denied.

For the permission denied message I may be able to run chmod +x abplayer on my laptop and then copy the file over to my tablet. The file is definitely there, so I don't know why I get the not found message.

Have you tried to run the abplayer file and get it to work? If so, can you post you exact procedure, step by step, so I can delete the file and try again?

jldiaz 2008-04-14 22:15

Re: aUDIOBOOK?
 
Quote:

Originally Posted by MstPrgmr (Post 169817)
yea, i dunno. 1/2 the time i get permission denied. the other 1/2 i get abplayer not found. i am now strictly getting abplayer not found. i will reflash later and try again i guess

Try this (assuming that you have abplayer and test.mp3 at /home/)

Code:

sh /home/abplayer /home/test.mp3
Please, if possible make a copy&paste of the output, do not type it. If you type, read carefully. Also, double check that you correctly copied the original script. It works for me, and apparently also for benson.

Btw, /home is not a good place to leave things. Better at /home/user, which is you user folder.

Benson 2008-04-14 22:26

Re: aUDIOBOOK?
 
I don't have mplayer, alas.

Try going to where abplayer currently lives, and
Code:

pwd
ls -l abplayer
cat abplayer

, and copy-and-paste the whole session here.

suitti 2008-04-15 14:55

Re: aUDIOBOOK?
 
I use Media Player. What i'd like to do is stuff the book into a directory and have Media Player play the directory. It can't. But it can play from a play list. But it can't create play lists.

So i wrote this shell script, and run it from xterm.

#!/bin/sh
for i in $1/*.mp3 ; do
echo `pwd`/$i >> $1.mp3
done

I call it 'mkplaylist'. I have it on my root filesystem. Use
chmod +x mkplaylist
to make it executable. For example:
cd /media/mmc2/Audio
ls
Eldest
mkplaylist Eldest
ls
Eldest Eldest.m3u
Then, use Open in Media Player, select Eldest.m3u from the list.

On close, Media Player remembers the last track you played.

Unfortunately, if you want to listen to something else, like a pod cast,
you need to remember where you were in your book.

I used to have mkplaylist on the SD card. And, the SD card was VFAT. So, i'd say:
sh mkplaylist Eldest
to get it to run (can't run stuff from VFAT). But now i use ext3 on my SD card, so this is moot for me.

I have xmms installed. However, it sometimes drops the last few seconds of a track. No idea why or what circumstances. But i'll often use xmms to listen to other stuff. Media Player then remembers where i was in my book. I use mplayer to watch movies.

But i use an iPod in the car, etc., because the buttons work one handed.

Benson 2008-04-15 16:54

Re: aUDIOBOOK?
 
Mediaplayer can make playlists, but I don't think it can auto-generate one from a directory.

Here's a simpler version, though:
Code:

#!/bin/sh
ls `pwd`/$1/*.mp3 > $1.m3u

:p
Not quite equivalent to yours, as this wipes the playlist if it already exists; I think this is more useful, but if you wanted it to append, you can change > to >>, of course.

Edit: Oh, by the way, ditch media player, use mpd and powerlaunch, and the N800's one-handed, too. Or write your own non-powerlaunch app (could even live in a terminal), just to intercept keypresses and call mpc, thus avoiding the complex generality of powerlaunch.

konus 2008-04-20 13:44

Re: aUDIOBOOK?
 
Quote:

Originally Posted by jldiaz (Post 169625)
You are right. Using python for everything is a tic. I accomplished this task with a simple shell script and a little of awk. Here is how:

Copy the following code to a file named, for example abplayer (from "audiobook player), or wathever you like:

Code:

#!/bin/sh
if test -f "$1".resume
then
 resumepoint=`cat "$1".resume`
else
 resumepoint=0
fi
mplayer -ss $resumepoint "$1"|awk 'BEGIN{RS="\r"}{if ($1=="A:") t=$2}END{print t}' > "$1".resume

Put this file in a place where your shell can find it (I have a "bin" folder in my $HOME, and a line in the .profile for adding this folder to the PATH variable). Make executable this file (chmod +x abplayer).

Then, use it from the command line (xterm) like this:
Code:

$ abplayer /route/to/audiobook.mp3
The audio begins to play. When you press 'q', the player is exited, and a new file is created, with name /route/to/audiobook.mp3.resume which contains the time in which the playback was quitted. Next time you use abeplay, it will search for this file. If it founds it, the playback is resumed from that point. If not, it is restarted again from the beginning.

If the player exits unexpectedly and the .resume file is corrupt, you have to delete it (or you can write a correct one with any editor, it only contains the time where the playback has to be resumed, in the format hh:mm:ss.ff, being ff any fraction of second, for example: 3:21.52)



I used mplayer because I have it already installed, and supports a wide range of formats. As for mpg123, I did not find it with apt-cache...

Thanks for idea.

My scripting skills are not so good... but this script works %)

Code:

#!/bin/sh
if [ -e $HOME/.mplayer/abook.plist ] && [ -z "$1" ]
        then
        LASTFILE=`cat $HOME/.mplayer/abook.resume | tail -n2 | awk -Fmp3 '{print $1}'`
        RESPOINT=`cat $HOME/.mplayer/abook.resume | tail -n1`
        FILESUM=`wc -l $HOME/.mplayer/abook.plist | awk '/[0-1]/ {print $1}'`
        CPLIST=`cat $HOME/.mplayer/abook.plist | grep -A$FILESUM "$LASTFILE"`
        elif [ -e $HOME/.mplayer/abook.plist ] && [ ! -z "$1" ]
                then
                echo " " > $HOME/.mplayer/abook.plist
                cd "$1"
                ABFILES=`ls -1`
                for I in $ABFILES
                do
                        echo "`pwd`/$I" >> $HOME/.mplayer/abook.plist
                done
                CPLIST=`cat $HOME/.mplayer/abook.plist`
                RESPOINT=0
        else
                echo "Usage: abplayer.sh /path/to/audiobook/dir/"
                exit
fi
mplayer -ss $RESPOINT $CPLIST > $HOME/.mplayer/abook.temp
awk '/Playing/ {print $2}' $HOME/.mplayer/abook.temp > $HOME/.mplayer/abook.resume
awk 'BEGIN{RS="\r"}{if ($1=="A:") t=$2}END{print t}' $HOME/.mplayer/abook.temp >> $HOME/.mplayer/abook.resume

how from last 3 lines make only one line? :/
thanks.

MstPrgmr 2008-04-20 14:18

Re: aUDIOBOOK?
 
ok, so i got the original abplayer script to work. any ideas how i can get mplayer to show stats such as current position in audiobook mp3 while the script is running?

jldiaz 2008-04-21 09:51

Re: aUDIOBOOK?
 
Quote:

Originally Posted by MstPrgmr (Post 172248)
ok, so i got the original abplayer script to work. any ideas how i can get mplayer to show stats such as current position in audiobook mp3 while the script is running?

Change the last line in the script by this one:

Code:

mplayer -ss $resumepoint "$1"|awk 'BEGIN{RS="\r"}{if ($1=="A:") {t=$2;printf $0"\r" > "/dev/stderr"}} END{print t}' > "$1".resume
The trick is: when awk detects a line beginning with "A:", it updates the variable t, and prints that line in the standard error output. This output is connected to the screen, so it is visible.

I use printf instead of print, because print always add a "\n" at the end, and this will result in a lot of lines printed. Using "\r", each line is overimposed on the previous one, and thus appears as a single line which updates itself.

I print $0, which means "the whole line as it was read", but if you prefer, you can parse it a bit. You have the current position in seconds in variable $2, and the current position in format "HH:MM:SS.dd" in variable $3. The total time in seconds is in $5, and the total time in format "HH:MM:SS.dd" in $7. Finally, $8 holds the CPU usage (not very useful, I would prefer a current position as a percentage of total). You can use this information and build your own status line, such as:

Code:

mplayer -ss $resumepoint "$1"|awk 'BEGIN{RS="\r"}{if ($1=="A:") {t=$2;printf "Position: %s of (%s  %5.1f%% played\r", $3, $7, $2*100/$5 > "/dev/stderr"}} END{print t}'  > "$1".resume
Also note that, while mplayer is runnig, you can use some keys to control it, such as the cursor keys (up and right to seek forward in different amounts, down and left to rewind), space or return to pause, and q to quit among others.

jldiaz 2008-04-21 10:06

Re: aUDIOBOOK?
 
Quote:

Originally Posted by konus (Post 172242)
Thanks for idea.
My scripting skills are not so good... but this script works %)

Code:

...(omitted)...

It did not work for me... I'm unsure why (because I don't fully understand its purpose, for example, the variable FILESUM). I have some ogg files, and your script relies on the assumption that only mp3 files are present. Besides, it requires the previous existence of file "abook.plist".

Anyway...

Quote:

Originally Posted by konus (Post 172242)
Code:

...
mplayer -ss $RESPOINT $CPLIST > $HOME/.mplayer/abook.temp
awk '/Playing/ {print $2}' $HOME/.mplayer/abook.temp > $HOME/.mplayer/abook.resume
awk 'BEGIN{RS="\r"}{if ($1=="A:") t=$2}END{print t}' $HOME/.mplayer/abook.temp >> $HOME/.mplayer/abook.resume

how from last 3 lines make only one line? :/
thanks.

What about the following? (not tested)

Code:

mplayer -ss $RESPOINT $CPLIST | awk 'BEGIN{RS="\r"}/Playing/{print $2}/^A:/{t=$2}END{print t}' > $HOME/.mplayer/abook.resume
The use of pipes in a single line avoids the existence of the temporal file, which is a good thing, because that file grows very faster (mplayer outputs status information about ten times per second!)

konus 2008-04-21 10:43

Re: aUDIOBOOK?
 
Quote:

Originally Posted by jldiaz (Post 172524)
It did not work for me... I'm unsure why (because I don't fully understand its purpose, for example, the variable FILESUM). I have some ogg files, and your script relies on the assumption that only mp3 files are present.

Anyway...

i forget, that i use bash on my IT :)
i dont know, why, but in busybox this script dont work...
so, here is for busybox:
Code:

#!/bin/sh
if  [ -z "$1" ]
        then
        LASTFILE=`cat $HOME/.mplayer/abook.resume | tail -n2 | awk -Fmp3 '{print $1}'`
        RESPOINT=`cat $HOME/.mplayer/abook.resume | tail -n1`
        FILESUM=`wc -l $HOME/.mplayer/abook.plist | awk '/[0-1]/ {print $1}'`
        CPLIST=`cat $HOME/.mplayer/abook.plist | grep -A$FILESUM "$LASTFILE"`
        else
                echo " " > $HOME/.mplayer/abook.plist
                cd "$1"
                ABFILES=`ls -1`
                for I in $ABFILES
                do
                        echo "`pwd`/$I" >> $HOME/.mplayer/abook.plist
                done
                CPLIST=`cat $HOME/.mplayer/abook.plist`
                RESPOINT=0
fi
mplayer -ss $RESPOINT $CPLIST > $HOME/.mplayer/abook.temp
awk '/Playing/ {print $2}' $HOME/.mplayer/abook.temp > $HOME/.mplayer/abook.resume
awk 'BEGIN{RS="\r"}{if ($1=="A:") t=$2}END{print t}' $HOME/.mplayer/abook.temp >> $HOME/.mplayer/abook.resume

about ogg...:

LASTFILE=`cat $HOME/.mplayer/abook.resume | tail -n2 | awk -Fmp3 '{print $1}'`

s/mp3/ogg/

and it will work...


Quote:

What about the following? (not tested)

Code:

mplayer -ss $RESPOINT $CPLIST | awk 'BEGIN{RS="\r"}/Playing/{print $2}/^A:/{t=$2}END{print t}' > $HOME/.mplayer/abook.resume
The use of pipes in a single line avoids the existence of the temporal file, which is a good thing, because that file grows very faster (mplayer outputs status information about ten times per second!)
Thanks.


All times are GMT. The time now is 03:14.

vBulletin® Version 3.8.8