GTK gui to start/stop aplay (or wavplay)

For discussions about programming, and for programming questions and advice


Moderator: Forum moderators

Post Reply
User avatar
greengeek
Posts: 1219
Joined: Thu Jul 16, 2020 11:06 pm
Has thanked: 349 times
Been thanked: 146 times

GTK gui to start/stop aplay (or wavplay)

Post by greengeek »

Not sure where to put this - but I would like to make a gtk gui that allows the user to select a wav file, then feed it to aplay and have start and stop buttons to control playback.

(Planning to use this when testing VanillaDpup which currently has no mplayer or deadbeef, but does have aplay - which handles wavs but not mp3)

Currently I just open a terminal and run aplay and type the file name but I would like to either have a file selector to choose the file or else rightclick the file and have it passed direct to the gui.

I can set up "open with" to get the file into aplay - but then I have no gui to stop playback and am relying on "killall aplay" to terminate it. I always get confused when trying to pass @u or similar arguments that specify the file name etc.

Does someone already have a basic gui on hand to achieve this please?

(VanillaDpup has very few libs and I am trying to get stuff done using the most basic of utilities)

EDIT Some useful options here:
- Thunor's PlayMusic pet works very well and is nicely configurable.
Doesnt matter if you only have basic audio utilities or massive codec/format support this simple utility is really worth a look:
viewtopic.php?p=74546#p74546

Last edited by greengeek on Mon Dec 05, 2022 1:15 am, edited 2 times in total.
User avatar
MochiMoppel
Posts: 1137
Joined: Mon Jun 15, 2020 6:25 am
Location: Japan
Has thanked: 18 times
Been thanked: 370 times

Re: GTK gui to start/stop aplay

Post by MochiMoppel »

greengeek wrote: Fri Dec 02, 2022 8:56 am

Does someone already have a basic gui on hand to achieve this please?

If "this" means controlling aplay then I don't know, but why not use ffplay (or avplay, depending on your distro)?

As GUI controls use mouse or better use the keyboard:

Code: Select all

FFplay window keyboard shortcuts:
PageUp      go to end
PageDown    go back to start
Right/Left  10sec forward/back
Up/Down     60sec forward/back
Space       pause/restart
Esc or Q    quit
Last edited by MochiMoppel on Fri Dec 02, 2022 9:35 am, edited 1 time in total.
User avatar
Jasper
Posts: 1654
Joined: Wed Sep 07, 2022 1:20 pm
Has thanked: 712 times
Been thanked: 378 times

Re: GTK gui to start/stop aplay

Post by Jasper »

@greengeek

If you want to build your own Gui you can grab the source file here:

https://code.google.com/archive/p/gtkdialog/

and a simple tutorial can be viewed here:

https://www.tecmint.com/gtkdialog-creat ... log-boxes/

Hope that helps!

jrb
Posts: 177
Joined: Sat Oct 24, 2020 5:47 pm
Has thanked: 5 times
Been thanked: 62 times

Re: GTK gui to start/stop aplay

Post by jrb »

aplay doesn't seem to have any pause function but here's a simple script that when you drag a wave file to it will open a terminal window and play your .wav file. To end play simply close window or Ctrl+c.
(Right click in any rox window and choose New-Script and then paste in the code.)

Code: Select all

#!/bin/sh
#open in terminal
tty -s; if [ $? -ne 0 ]; then xterm -hold -e "'$0' '$1'"; exit; fi

aplay "$1"

Cheers, J

some1
Posts: 71
Joined: Wed Aug 19, 2020 4:32 am
Has thanked: 17 times
Been thanked: 11 times

Re: GTK gui to start/stop aplay

Post by some1 »

User avatar
greengeek
Posts: 1219
Joined: Thu Jul 16, 2020 11:06 pm
Has thanked: 349 times
Been thanked: 146 times

Re: GTK gui to start/stop aplay

Post by greengeek »

MochiMoppel wrote: Fri Dec 02, 2022 9:15 am

If "this" means controlling aplay then I don't know, but why not use ffplay (or avplay, depending on your distro)?

Thanks MM - unfortunately Vanilla has no ffmpeg or avconv ootb - and at this stage I am trying to see what I can achieve with as little added as possible. I am a big fan of ffmpeg but for now it is not the solution for me (yet).
(I am just using aplay to get some background music while I troubleshoot and configure the basic Vanilla pup)

Jasper wrote: Fri Dec 02, 2022 9:35 am

If you want to build your own Gui you can grab the source file here:
https://code.google.com/archive/p/gtkdialog/
and a simple tutorial can be viewed here:
https://www.tecmint.com/gtkdialog-creat ... log-boxes/

Thank you - those are very handy. I will definitely find those useful.

some1 wrote: Fri Dec 02, 2022 7:13 pm

'Take a look:
https://oldforum.puppylinux.com/viewtopic.php?t=72116

Great link thanks. Some interesting ideas there!

User avatar
greengeek
Posts: 1219
Joined: Thu Jul 16, 2020 11:06 pm
Has thanked: 349 times
Been thanked: 146 times

Re: GTK gui to start/stop aplay

Post by greengeek »

jrb wrote: Fri Dec 02, 2022 4:17 pm

aplay doesn't seem to have any pause function but here's a simple script that when you drag a wave file to it will open a terminal window and play your .wav file. To end play simply close window or Ctrl+c.
(Right click in any rox window and choose New-Script and then paste in the code.)

Code: Select all

#!/bin/sh
#open in terminal
tty -s; if [ $? -ne 0 ]; then xterm -hold -e "'$0' '$1'"; exit; fi

aplay "$1"

Cheers, J

Thanks - working nicely. Of course now I want something extra :-)
Is there any way that this script could be modified to handle a whole directory of wavs dragged to it?
Cheers!

User avatar
greengeek
Posts: 1219
Joined: Thu Jul 16, 2020 11:06 pm
Has thanked: 349 times
Been thanked: 146 times

Re: GTK gui to start/stop aplay

Post by greengeek »

some1 wrote: Fri Dec 02, 2022 7:13 pm

'Take a look:
https://oldforum.puppylinux.com/viewtopic.php?t=72116

You know - all these years I have been reading the old forum - and only now did I see that Argolance's avatar is actually an animated gif - with a cheeky red tongue poking out at the end. Never noticed that before. :lol:

User avatar
greengeek
Posts: 1219
Joined: Thu Jul 16, 2020 11:06 pm
Has thanked: 349 times
Been thanked: 146 times

Re: GTK gui to start/stop aplay

Post by greengeek »

I can use aplay to play each file in a directory of .wav files using the following script placed inside the music (wav file) directory:

Code: Select all

#! /bin/bash
for FILE in *; do aplay $FILE; done

I would be keen to find out how to modify that code to play only wav files in a directory of mixed media files (eg wav, mp3, ogg, flv etc etc)
(ie skipping the non-wav files without errors and without white noise for non wav files)

EDIT: of course it is simple to do so - just change * to *.wav

Code: Select all

#! /bin/bash
for FILE in *.wav; do aplay $FILE; done
Last edited by greengeek on Mon Dec 05, 2022 4:54 am, edited 1 time in total.
User avatar
puppy_apprentice
Posts: 661
Joined: Tue Oct 06, 2020 8:43 pm
Location: land of bigos and schabowy ;)
Has thanked: 4 times
Been thanked: 107 times

Re: GTK gui to start/stop aplay

Post by puppy_apprentice »

Code: Select all

#!/bin/bash
shopt -s nullglob
for FILE in *.wav; do aplay $FILE; done
shopt -u nullglob
User avatar
greengeek
Posts: 1219
Joined: Thu Jul 16, 2020 11:06 pm
Has thanked: 349 times
Been thanked: 146 times

Re: GTK gui to start/stop aplay

Post by greengeek »

puppy_apprentice wrote: Sat Dec 03, 2022 8:47 am

Code: Select all

#!/bin/bash
shopt -s nullglob
for FILE in *.wav; do aplay $FILE; done
shopt -u nullglob

Nice. Thanks! Will experiment with this.

HerrBert
Posts: 340
Joined: Mon Jul 13, 2020 6:14 pm
Location: Germany, NRW
Has thanked: 17 times
Been thanked: 114 times

Re: GTK gui to start/stop aplay

Post by HerrBert »

greengeek wrote: Sat Dec 03, 2022 8:05 am

I can use aplay to play each file in a directory of .wav files using the following script placed inside the music (wav file) directory:

Code: Select all

#! /bin/bash

for FILE in *; do aplay $FILE; done

I would be keen to find out how to modify that code to play only wav files in a directory of mixed media files (eg wav, mp3, ogg, flv etc etc)
(ie skipping the non-wav files without errors and without white noise for non wav files)

Maybe thunor's PlayMusic - A Simple Lightweight GUI for Audio Players can do what you want.
Links on the old forum thread are broken...
I recall it is also part of gtkdialog source
github: https://github.com/oshazard/gtkdialog/t ... /playmusic

jrb
Posts: 177
Joined: Sat Oct 24, 2020 5:47 pm
Has thanked: 5 times
Been thanked: 62 times

Re: GTK gui to start/stop aplay

Post by jrb »

HerrBert wrote: Sat Dec 03, 2022 10:42 am

Maybe thunor's PlayMusic - A Simple Lightweight GUI for Audio Players can do what you want.
Links on the old forum thread are broken...

It's available in PPM (puppy-noarch-official). It says "mplayer" but IIRC you can set it to any audioplayer in the config file it creates in /root. You can also specify different players for different file types.

User avatar
fredx181
Posts: 2648
Joined: Tue Dec 03, 2019 1:49 pm
Location: holland
Has thanked: 293 times
Been thanked: 1042 times
Contact:

Re: GTK gui to start/stop aplay

Post by fredx181 »

Links on the old forum thread are broken...

Not very convenient, but workaround, change in the url: "murga-linux.com/puppy" to "oldforum.puppylinux.com"
For example change:
http://murga-linux.com/puppy/viewtopic.php?p=983208#983208
to:
http://oldforum.puppylinux.com/viewtopic.php?p=983208#983208

And paste in the address bar.

User avatar
greengeek
Posts: 1219
Joined: Thu Jul 16, 2020 11:06 pm
Has thanked: 349 times
Been thanked: 146 times

Re: GTK gui to start/stop aplay

Post by greengeek »

HerrBert wrote: Sat Dec 03, 2022 10:42 am

Maybe thunor's PlayMusic - A Simple Lightweight GUI for Audio Players can do what you want.

Excellent suggestion - thanks

jrb wrote: Sat Dec 03, 2022 1:08 pm

It's available in PPM (puppy-noarch-official). It says "mplayer" but IIRC you can set it to any audioplayer in the config file it creates in /root. You can also specify different players for different file types.

Thanks for the tip. Yes it is strange that "mplayer" is part of the name when it does not require mplayer at all.

In fact this utility is a pretty good fit for my needs. Surprisingly it defaults to using wavplay which I did not realise is already part of VanillaDpup.

Nice little gui and the only problem so far is that it takes quite a bit of time to sort through the music to find only wav files (which is all that the aplay and/or wavplay components can handle). Not a big issue and it seemed to get faster as time went on.

I still have plans to build my own gui using some of the other suggestions here. (I particularly liked the shopt glob method which seemed to work well in script form. I want to build that into a gui if i can)

Direct link to Thunors pet in ibiblio no-arch repository:
https://distro.ibiblio.org/puppylinux/p ... noarch.pet

PlayMusicGui.jpg
PlayMusicGui.jpg (11.63 KiB) Viewed 690 times
User avatar
greengeek
Posts: 1219
Joined: Thu Jul 16, 2020 11:06 pm
Has thanked: 349 times
Been thanked: 146 times

Re: GTK gui to start/stop aplay (or wavplay)

Post by greengeek »

Using puppy_apprentice's shopt nullglob syntax I made 3 scripts which I can put in my music directory.

They allow me to start playing the wavs, step to the next wav, or kill the wav playing altogether.

I plan to make a gtk gui run these but for now they give me the basic control I need.

Unzip the attachment into the Music directory where the wavs can be found and click on each script as required.
(The 0- prefix helps keep the scripts displayed at the top of the window so you don't have to scroll too far to find them)
(The scripts must be "loose" inside the music directory - not buried in a subdirectory)

wav-aplay_scripts.jpg
wav-aplay_scripts.jpg (5.01 KiB) Viewed 683 times
wav-aplay.zip
(1.02 KiB) Downloaded 26 times
Post Reply

Return to “Programming”