Reply
Thread Tools
jldiaz's Avatar
Posts: 48 | Thanked: 40 times | Joined on Apr 2008 @ Spain
#21
Originally Posted by MstPrgmr View Post
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.
__________________
--ル Diaz
 
Benson's Avatar
Posts: 4,930 | Thanked: 2,272 times | Joined on Oct 2007
#22
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's Avatar
Posts: 96 | Thanked: 7 times | Joined on Sep 2007
#23
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's Avatar
Posts: 4,930 | Thanked: 2,272 times | Joined on Oct 2007
#24
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

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's Avatar
Posts: 41 | Thanked: 21 times | Joined on Apr 2008 @ Nurnberg
#25
Originally Posted by jldiaz View Post
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.
 
Posts: 118 | Thanked: 16 times | Joined on Sep 2007
#26
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's Avatar
Posts: 48 | Thanked: 40 times | Joined on Apr 2008 @ Spain
#27
Originally Posted by MstPrgmr View Post
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.
__________________
--ル Diaz

Last edited by jldiaz; 2008-04-21 at 10:12. Reason: Removing spureous line
 
jldiaz's Avatar
Posts: 48 | Thanked: 40 times | Joined on Apr 2008 @ Spain
#28
Originally Posted by konus View Post
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...

Originally Posted by konus View Post
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!)
__________________
--ル Diaz
 
konus's Avatar
Posts: 41 | Thanked: 21 times | Joined on Apr 2008 @ Nurnberg
#29
Originally Posted by jldiaz View Post
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...


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.
 
Reply


 
Forum Jump


All times are GMT. The time now is 13:22.