Open a window and play a song
I start ocarina with a file. I play the song right away, and open a window so that gtk_main() can quit when closed.
This commit is contained in:
parent
c0ace6fed6
commit
53d8718053
|
@ -2,11 +2,25 @@
|
|||
#include <iostream>
|
||||
using namespace std;
|
||||
|
||||
#include <ocarina/window.h>
|
||||
#include <libsaria/libsaria.h>
|
||||
|
||||
int main()
|
||||
void ocarina_init(int argc, char **argv)
|
||||
{
|
||||
gtk_init(&argc, &argv);
|
||||
window_init();
|
||||
gtk_main();
|
||||
}
|
||||
|
||||
void ocarina_quit()
|
||||
{
|
||||
gtk_main_quit();
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
print("Ocarina 5.0");
|
||||
libsaria_init();
|
||||
libsaria_init(argc, argv);
|
||||
ocarina_init(argc, argv);
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -0,0 +1,23 @@
|
|||
|
||||
#include <ocarina/ocarina.h>
|
||||
#include <ocarina/window.h>
|
||||
|
||||
static GtkWidget *window;
|
||||
|
||||
void destroy_window(GtkWidget *widget, GdkEvent *event, gpointer data)
|
||||
{
|
||||
ocarina_quit();
|
||||
}
|
||||
|
||||
void window_resize(int w, int h)
|
||||
{
|
||||
gtk_window_resize(GTK_WINDOW(window), w, h);
|
||||
}
|
||||
|
||||
void window_init()
|
||||
{
|
||||
window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
|
||||
g_signal_connect(window, "destroy", G_CALLBACK(destroy_window), NULL);
|
||||
window_resize(800, 600);
|
||||
gtk_widget_show(window);
|
||||
}
|
|
@ -0,0 +1,10 @@
|
|||
#ifndef LIBSARIA_AUDIO_H
|
||||
#define LIBSARIA_AUDIO_H
|
||||
|
||||
extern "C" {
|
||||
#include <gst/gst.h>
|
||||
}
|
||||
|
||||
void audio_init(int, char **);
|
||||
|
||||
#endif /* LIBSARIA_AUDIO_H */
|
|
@ -3,6 +3,6 @@
|
|||
|
||||
#include <libsaria/print.h>
|
||||
|
||||
void libsaria_init();
|
||||
void libsaria_init(int, char**);
|
||||
|
||||
#endif /* LIBSARIA_H */
|
||||
|
|
|
@ -1,6 +1,9 @@
|
|||
#ifndef LIBSARIA_PRINT
|
||||
#define LIBSARIA_PRINT
|
||||
|
||||
#include <string>
|
||||
using namespace std;
|
||||
|
||||
void print(string item);
|
||||
|
||||
#endif /* LIBSARIA_PRINT */
|
||||
|
|
|
@ -0,0 +1,40 @@
|
|||
|
||||
#include <libsaria/audio.h>
|
||||
#include <libsaria/libsaria.h>
|
||||
|
||||
static GstElement *player;
|
||||
static string cur_file;
|
||||
|
||||
void change_state(GstState new_state)
|
||||
{
|
||||
gst_element_set_state(GST_ELEMENT(player), new_state);
|
||||
}
|
||||
|
||||
void reset()
|
||||
{
|
||||
cur_file = "";
|
||||
change_state(GST_STATE_NULL);
|
||||
}
|
||||
|
||||
void load_file(string file)
|
||||
{
|
||||
string uri = "file://" + file;
|
||||
cur_file = file;
|
||||
g_object_set(G_OBJECT(player), "uri", uri.c_str(), NULL);
|
||||
}
|
||||
|
||||
void play()
|
||||
{
|
||||
change_state(GST_STATE_PLAYING);
|
||||
}
|
||||
|
||||
void audio_init(int argc, char **argv)
|
||||
{
|
||||
print("Initializing audio...");
|
||||
gst_init(&argc, &argv);
|
||||
|
||||
player = gst_element_factory_make("playbin2", "player");
|
||||
if (argc > 1)
|
||||
load_file(argv[1]);
|
||||
play();
|
||||
}
|
|
@ -2,9 +2,11 @@
|
|||
#include <iostream>
|
||||
using namespace std;
|
||||
|
||||
#include <libsaria/audio.h>
|
||||
#include <libsaria/libsaria.h>
|
||||
|
||||
void libsaria_init()
|
||||
void libsaria_init(int argc, char **argv)
|
||||
{
|
||||
print("Initializing libsaria");
|
||||
audio_init(argc, argv);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue