|
- /***************************************************************************
- * Copyright (C) 2006 by root *
- * root@localhost.localdomain *
- * *
- * This program is free software; you can redistribute it and/or modify *
- * it under the terms of the GNU General Public License as published by *
- * the Free Software Foundation; either version 2 of the License, or *
- * (at your option) any later version. *
- * *
- * This program is distributed in the hope that it will be useful, *
- * but WITHOUT ANY WARRANTY; without even the implied warranty of *
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
- * GNU General Public License for more details. *
- * *
- * You should have received a copy of the GNU General Public License *
- * along with this program; if not, write to the *
- * Free Software Foundation, Inc., *
- * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
- ***************************************************************************/
- #include < gtk/gtk.h > //gtk/gtk.h
- #include < fmod.h > //fmod. h
- #include < fmod_errors.h > // fmod_errors.h
- #include < stdio.h > //stdio.h
- FMOD_SYSTEM *FModsystem = NULL;
- FMOD_SOUND *sound1 = NULL;
- FMOD_RESULT result = FMOD_OK;
- FMOD_CHANNEL *channel = NULL;
- void ERRCHECK(FMOD_RESULT result)
- {
- if(result != FMOD_OK)
- {
- printf("FMOD error! (%d) %s\n", result, FMOD_ErrorString(result));
- exit(-1);
- }
- }
- //----------
- // 初始化FMOD对象
- //----------
- int FMOD_Init()
- {
- unsigned int version = 0;
-
- result = FMOD_System_Create(&FModsystem);
- ERRCHECK(result);
- result = FMOD_System_GetVersion(FModsystem, &version);
- ERRCHECK(result);
- if(version < FMOD_VERSION)
- {
- printf("Error! You are using an ole version of FMOD %08x. This program requires %08x\n",\
- version, FMOD_VERSION);
- getch();
- return 0;
- }
-
- result = FMOD_System_Init(FModsystem, 32, FMOD_INIT_NORMAL, NULL);
- ERRCHECK(result);
- return 0;
- }
- //-------------
- //播放
- //-------------
- int FMOD_PlayFile()
- {
-
- FMOD_SOUND *sound2, *sound3;
-
-
- int key = 0;
-
- int playing = 0;
- if( channel != NULL)
- {
- FMOD_Channel_IsPlaying(channel, &playing);
-
- if(playing)
- {
- int paused = 0;
- FMOD_Channel_GetPaused(channel, &paused);
- FMOD_Channel_SetPaused(channel, !paused);
- return 0;
- }
- }
- result = FMOD_System_CreateStream(FModsystem, "/windows/Server/03.ogg", FMOD_DEFAULT, 0, &sound1);
- ERRCHECK(result);
-
- printf("=====================================================\n");
- printf("PlayStream Example Copyright (c) Firelight Technologies 2004-2005.\n");
-
- result = FMOD_System_PlaySound(FModsystem, FMOD_CHANNEL_FREE, sound1, 0, &channel);
- ERRCHECK(result);
- return 1;
- }
- //---------------
- // 释放FMOD音频对象
- //---------------
- void ReleaseFMOD()
- {
- result = FMOD_Sound_Release(sound1);
- ERRCHECK(result);
- result = FMOD_System_Close(FModsystem);
- ERRCHECK(result);
- result = FMOD_System_Release(FModsystem);
- ERRCHECK(result);
- }
- //-----------------------
- // 打开
- //-----------------------
- void callback(GtkWidget *widget,
- gpointer data)
- {
- g_print("Hello again - %s was pressed\n", (gchar*)data);
- }
- //-------------------------------
- // 打开
- //-------------------------------
- void Open(GtkWidget *widget, gpointer data)
- {
- g_print("Open File - %s \n", (gchar*)data);
- }
- void Pause(GtkWidget *widget, gpointer data)
- {
-
- }
- void Stop(GtkWidget *widget, gpointer data)
- {
- g_print("Stop Play - %s was pressed\n", (gchar*)data);
- }
- void Close(GtkWidget *widget, gpointer data)
- {
- g_print("Close Play - %s was pressed\n", (gchar*)data);
- }
- void Play(GtkWidget *widget, gpointer data)
- {
- FMOD_PlayFile();
- }
- //--------------------------
- // 删除事件
- //--------------------------
- gint delete_event(GtkWidget *widget,
- GdkEvent *event,
- gpointer data)
- {
- gtk_main_quit();
- return FALSE;
- }
- //----------------------
- // 入口函数
- //----------------------
- int main(int argc, char *argv[])
- {
- GtkWidget *window = NULL;
- GtkWidget *button = NULL;
- GtkWidget *box1 = NULL;
-
- FMOD_Init();
- gtk_init(&argc, &argv);
-
- //显示窗口 并设置窗口标题
- window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
- gtk_window_set_title(GTK_WINDOW(window), "PlayAudioer");
- g_signal_connect(G_OBJECT(window), "delete_event",
- G_CALLBACK(delete_event), NULL);
- gtk_container_set_border_width(GTK_CONTAINER(window), 10);
- box1 = gtk_hbox_new(FALSE, 0);
- gtk_container_add(GTK_CONTAINER(window), box1);
- //第一个按钮
- button = gtk_button_new_with_label("打开");
- g_signal_connect(G_OBJECT(button), "clicked",
- G_CALLBACK(Open), "button1");
- gtk_box_pack_start(GTK_BOX(box1), button, TRUE, TRUE, 0);
- gtk_widget_show(button);
-
- //第二个按钮
- button = gtk_button_new_with_label("暂停");
- g_signal_connect(G_OBJECT(button), "clicked",
- G_CALLBACK(Pause), "button2");
- gtk_box_pack_start(GTK_BOX(box1), button, TRUE, TRUE, 0);
- gtk_widget_show(button);
- //第三个按钮
- button = gtk_button_new_with_label("停止");
- g_signal_connect(G_OBJECT(button), "clicked",
- G_CALLBACK(Stop), "button3");
- gtk_box_pack_start(GTK_BOX(box1), button, TRUE, TRUE, 0);
- gtk_widget_show(button);
- //第四个按钮
- button = gtk_button_new_with_label("关闭");
- g_signal_connect(G_OBJECT(button), "clicked",
- G_CALLBACK(Close), "button4");
- gtk_box_pack_start(GTK_BOX(box1), button, TRUE, TRUE, 0);
- gtk_widget_show(button);
- //第五个按钮
- button = gtk_button_new_with_label("播放");
- g_signal_connect(G_OBJECT(button), "clicked",
- G_CALLBACK(Play), "button5");
- gtk_box_pack_start(GTK_BOX(box1), button, TRUE, TRUE, 0);
- gtk_widget_show(button);
- //--------------------
- // 显示包装盒和窗口
- //--------------------
- gtk_widget_show(box1);
- gtk_widget_show(window);
- gtk_main();
- ReleaseFMOD();
- return 0;
- }
复制代码
编译:
gcc -O3 -o playsound -I/usr/local/include/fmodex -include/work/BzipB/fmodapi40453linux64/examples/common/wincompat.h hell.c /usr/local/lib/libfmodex64.so -pthread `pkg-config --cflags --libs gtk+-2.0`
具体路径替换为自己的。 |
|