• 大小: 9.45MB
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2023-10-08
  • 语言: 其他
  • 标签: gtk  mp3  播放器  linux  

资源简介

一个基于gtk实现的mp3播放器,十分小巧,代码简单,仅200行,供学习gtk的初级同学使用

资源截图

代码片段和文件信息

/* file: gplayer.c
 */
#include “gplayer.h“
#include 

static gboolean gplayer_init(GPlayer *player);
/* 
 */
static gboolean cb_bus(GstBus *bus GstMessage *msg gpointer data)
{
GPlayer *player= (GPlayer*)data;
GError *err;
gchar *debug;

GstTagList *tags;
gchar *title;
gchar *artist;
gchar *album;

gint time;

switch(GST_MESSAGE_TYPE(msg) )
{
case GST_MESSAGE_ERROR:
gst_message_parse_error(msg &err &debug);
g_print(“Error: %s\n“ err->message);
g_error_free(err);
g_free(debug);
;
break;
case GST_MESSAGE_EOS:
;
break;
case GST_MESSAGE_TAG:
gst_message_parse_tag(msg &tags);
if(gst_tag_list_get_string(tags GST_TAG_title &title)&& 
   gst_tag_list_get_string(tags GST_TAG_ARTIST &artist)&& 
   gst_tag_list_get_string(tags GST_TAG_ALBUM &album) )
{
g_print(“title: %s\nArtist: %s\nAlbum: %s\n“ 
title artist album);
}
gst_tag_list_free(tags);
if(-1!=gplayer_get_duration(player) )
{
time= gplayer_get_duration(player);
g_print(“Time: %d:%ds\n“ time/60 time%60 );
}
break;
default:
break;
}
return TRUE;
}

static gboolean cb_timeout(gpointer data)
{
GPlayer *player= (GPlayer*)data;
gint gone= gplayer_get_pos(player);
gdouble progress= gplayer_get_progress(player);

gdouble volume= 1.0;
gboolean mute= FALSE;

g_print(“Progress: %d:%ds\t%lf\n“ gone/60 gone%60 progress );
if(progress>0.25&& progress<0.35)
gplayer_set_progress(player 0.75);

gplayer_set_volume(player volume+10*progress ); 
volume= gplayer_get_volume(player);
gplayer_set_mute(player mute+( (progress>0.5)?1:0 ) ); 
mute= gplayer_get_mute(player);
g_print(“Volume: %lf\nMute: %d\n“ volume mute);

return TRUE;
}

/* 
 */
GPlayer *gplayer_create()
{
GPlayer *player= NULL;
GstElement *play2;
GstBus *bus;

player= (GPlayer*)malloc(sizeof(GPlayer) );
if(NULL!= player)
{
play2= gst_element_factory_make(“playbin2“ “play2“);

bus= gst_pipeline_get_bus(GST_PIPELINE(play2) );
gst_bus_add_watch(bus cb_bus player);
gst_object_unref(GST_object(bus) );

gst_element_set_state(play2 GST_STATE_NULL);
player->play2= play2;
}
else
{
}
gplayer_init(player);

return player;
}

static gboolean gplayer_init(GPlayer *player)
{
/*g_object_set(G_object(player->play2) “volume“ player->volume NULL);
g_object_set(G_object(player->play2) “mute“ player->mute NULL);*/

g_timeout_add(1000 cb_timeout player);
g_object_set(G_object(player->play2) “uri“ “file:///mnt/hgfs/share/gplayer/mp3/1.mp3“ NULL);
gst_element_set_state(player->play2 GST_STATE_PLAYING);

return TRUE;
}


gboolean gplayer_play(GPlayer *player)
{
return TRUE;
}

gboolean gplayer_pause(GPlayer *player)
{
gboolean res= TRUE;
if(GST_STATE_CHANGE_FAILURE== gst_element_set_state(player->play2 GST_STATE_PAUSED) )
res= FALSE;
return res;
}


gboolean gplayer_next(GPlayer 

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件       5522  2011-07-22 14:17  gplayer\gplayer.c

     文件       5516  2011-06-30 20:30  gplayer\gplayer.c.bak

     文件       1223  2011-06-27 15:42  gplayer\gplayer.h

     文件        359  2011-06-27 10:03  gplayer\makefile

     文件    4127762  2011-03-17 22:49  gplayer\mp3\1.mp3

     文件    3658440  2010-11-19 20:09  gplayer\mp3\2.mp3

     文件    2338434  2011-04-12 22:17  gplayer\mp3\3.mp3

     文件        241  2011-06-27 09:39  gplayer\PlayerTest.c

     目录          0  2011-07-17 16:24  gplayer\mp3

     目录          0  2011-07-22 14:17  gplayer

----------- ---------  ---------- -----  ----

             10137497                    10


评论

共有 条评论