Reply
Thread Tools
nicolai's Avatar
Posts: 1,637 | Thanked: 4,424 times | Joined on Apr 2009 @ Germany
#1
Hi,

is there a simple API to play a short part of a sound file.
I need this to play a sound preview, the user sees a list
of sound files and everytime he selects another file, I want
to play some seconds from this file.
(Just like the ringtone selector in the profiles settings dialog)

regards nicolai
 
noobmonkey's Avatar
Posts: 3,203 | Thanked: 1,391 times | Joined on Nov 2009 @ Worthing, England
#2
do a search on gstreamer tools - i'm pretty sure it should be able to do it
I'm thinking allong th elines of a script that

# Create the player_name sink
player_name = gst.element_make_factory(“playbin”, “Multimedia Player”)
# Create the fake video sink
fake_video_sink = gst.element_make_factory(“fakesink”, “Fake sink for Videos”)
#Add the fake video sink to the player
player_name.set_property(“videosink”, fake_video_sink)
#Set the file
player_name.set_property(“uri”, “file:///home/peter/mymusic.mp3”)
#Set the State
player_name.set_state(gst.PLAYING)
#Play the file
.....
#After x seconds run gst.STATE_PAUSED or gst.STATE_NULL — Used to stop file
.......


Pretty sure you can use self.time_format = gst.Format(gst.FORMAT_TIME) to figure out where to start / stop too...
__________________
----------- Follow me on Twitter here
----------- My Photography Website and Blog is here
----------- Author of the N900 Health Check Application ----------- New Version in Extras Devel (Dec 2010 - 2.9.10)
----------- Are you on the N900 World Map? - http://pininthemap.com/maemo - masterpin: shotgun
----------- What apps do you want to see on the n900 or in MeeGo in the future? -
 

The Following 3 Users Say Thank You to noobmonkey For This Useful Post:
nicolai's Avatar
Posts: 1,637 | Thanked: 4,424 times | Joined on Apr 2009 @ Germany
#3
Thank you,

this is python code, right?
I need this for a gtk program written in c.
I already found some gstreamer code snippets, but
dont know how much code is needed to initialize and
use gstreamer. I hoped there were a simple API
preferable something in the hildon framework.

nicolai
 
nicolai's Avatar
Posts: 1,637 | Thanked: 4,424 times | Joined on Apr 2009 @ Germany
#4
Thank you again noobmonkey,

this hint was actually more helpful than I thought.
Here is a short code snippets how to play a sound
with gstreamer in C.

Code:
#include <stdlib.h>
#include <gst/gst.h>

// build with gcc -o sound_player sound_player.c $(pkg-config --cflags --libs gstreamer-base-0.10)
int
main (int argc, char *argv[])
{
  gst_init (&argc,&argv);
  GstElement *player;
  GMainLoop* loop;
  loop = g_main_loop_new (NULL, FALSE);
  if (argc != 2) {
    g_print ("usage: %s <audio filename-uri (file:///fullpath/name.mp3)>\n", argv[0]);
    exit (-1);
  }
  player = gst_element_factory_make ("playbin2", "Multimedia Player");
  g_object_set (G_OBJECT (player), "uri", argv[1], NULL);
  g_assert (player != NULL);
  gdouble v = 0.5;
  g_object_set(player, "volume", v);
  int ret = gst_element_set_state (player, GST_STATE_PLAYING);
  g_main_loop_run(loop);
  exit (0);
}
 

The Following 6 Users Say Thank You to nicolai For This Useful Post:
bingomion's Avatar
Posts: 528 | Thanked: 345 times | Joined on Aug 2010 @ MLB.AU
#5
Hello,
Does anyone know a commandline exe to play a wav that pulse or silences the current media player?

I had a look at osso-af-utils.. but it doesn't make sense to me what these exe's do.
Looks like espeaktime uses PulseAudio properties via the PULSE_PROP env var.

espeaktime-now.sh:
export PULSE_PROP="module-stream-restore.id=x-maemo-applet-profiles event.id=ringtone-preview"
espeak -w $fname "${@}"
play-sound $fname
rm -f $fname

This doesn't stop/silence the current audio and plays over it
 
Reply


 
Forum Jump


All times are GMT. The time now is 10:05.