1. Breif Introduction:
This applicaiton is an audio player which based Gstreamer as its multimedia
solution and Gtk+ as it user interface. It also used some mid-wares which
written by other members of LiPS, such as libgpephone, libgemwidget, and so on.
At the following, I will introduce them respectively.
2. Overview:
(1) Gstreamer: If you want to know the advanced usage, you could get some
hints from FAQ and manul.pdf of Gstreamer. In this program, I just used six
plugins to play mp3 files. They are filesrc, id3demux, mad, audioconvert, volume
and esdsink. Although this program just built a mp3 decode pipeline yet, I
provide an easy way to add other decoders.
(2) Gtk+-2.0: I just used some several widgets to implement this program,
such as GtkFixed, GtkLabel, GtkTreeView and so on.
(3) GLib-2.0: I used GIOChannel to implement file operations, GDir to read
list file in a specified directory and GList to manage the play list.
(4) libgpewidget: This library provided us with an unique top level GtkWindow
named GpeSKWindow. This window encapsulate a soft key press event. If soft key
pressed, this window will emit a "softkey_activated" signal and popup the menu
automatically if you had specified.
(5) libgemwidget: This library provided some useful widgets for mobile phone,
such as GtkAutoScrolledWindow, GemTreeView and so on. It also defined an unique
resource access to all LiPS applicaitons.
(6) filechooser: This widget is included in libgemwidget. It is a simple but
powerful file browser for Linux phone.
3. Design and Concept:
This program can be devided into three parts: file operations, multimedia
solution and user interface.
(1) file operations: This parts was implemented in the file named "file.c".
It provided the upper programmer with a way to create, modify, remove play list
files. It also provided an easy way to read and write configuration informations
when the program terminated.
(2) multimedia solution: This parts was implemented in the file name
"gstplayer.c". Because all audio pipelines have the same source and sink, the
difference between them is decoder. So I used the method similar to GstPlayBin:
encapsulate "audioconvert", "volume" and "esdsink" to a sink_bin and make a
decoder manager to manage decoders.
(3) user interface: There are two picutres in this directory. Those are flow
charts of this program. I use one file to implement one page. For example: the
listmanager.c implement the page of listmanager. All pages' top levle window is
a GpeSKWindow.
4. General structure and APIs:
(1) file.c file.h
typedef struct _APFileItem {
gchar *name; // name of audio files.
gchar *path; // path of audio files.
} APFileItem;
Upper programmers can read and write the default play list to a file by using
"ap_file_read_play_list" and "ap_file_save_play_list". To merge a temp play
list to the default one by using "ap_file_update_play_list", merge two temp play
list by using "ap_file_merge_list". To convert the selections which get from
filechooser to a play list by using "ap_file_collect_list". If you want delete a
file item from the default play list, you can use "ap_file_del_item_play_list".
"ap_file_write_conf" to write configuration and "ap_file_read_conf" to read
configuration.
(2) gstplayer.c gstplayer.h
To play a specified song, at first, you should set the location of the audio
file by using "ap_gst_player_set_location" and then set the player's state to
GST_STATE_PLAYING if the return of "ap_gst_player_set_location" is SET_SUCCESS.
typedef enum _SetLocReturn {
PLAYER_NEED_INIT, // the player is not initialized yet.
FILE_NOT_EXIST, // the file you specified is not exist.
UNKONWN_FILE_TYPE, // the file you specified is not supported yet.
SET_SUCCESS // set success.
} SetLocReturn;
I make an instance of DecManager to manage decoders. One file type map to one
decoder, and the pipeline can select the proper decoder according to the file
type automatically.
typedef struct _DecManager { typedef enum _FileType {
GstElement *mp3decoder; TYPE_UNKNOW,
GstElement *wavdecoder; TYPE_MP3,
} DecManager; TYPE_WAV
} FileType;
(3) user interface
The major of pages consist of GpsSkWindow, GtkImage, GemTreeView. At the
following, I will only describe the implementation of the most complex page:
playpage.
typedef struct _PPageManager {
GtkWidget *window;
/**
* The markup of the volume.
*/
GtkWidget *volume;
/**
* The information labels. Such as "Title", "Artist" and so on.
*/
GtkWidget *info_list[7];
/**
* Two labels which indicate the duration and position of the playing song.
*/
GtkWidget *position;
GtkWidget *duration;
/**
* dur_val is used to record the duration of the playing song and to estimate
* is there a new song.
*/
gint64 dur_val;
/**
* The progress scale of the song.
*/
GtkWidget *progress;
/**
* Five effection icons.
*/
GtkWidget *effect_icons[5]; //0 up 1 left 2 down 3 right 4 pause
GtkUIManager *ui_manager;
GtkActionGroup *action_group;
/**
* Play model of the player.
*/
PlayModel play_model;
/**
* The handle of the player pipeline.
*/
GstElement *player;
GstState play_state;
/**
*
*/
gboolean player_inited;
GList *play_list;
gchar *cur_file;
guint update_id;
} PPageManager;
The effection icons are all added to a GtkFixed at the same position, and
show the proper icon according to the state of the player.