libsaria: Tell tracks if they should play when loaded
This should set the gst pipeline to the correct state when the song is loaded, rather than pausing after telling it to play. Signed-off-by: Bryan Schumaker <bjschuma@gmail.com>
This commit is contained in:
parent
7dab47783b
commit
c3ba90f900
|
@ -26,7 +26,7 @@ namespace libsaria
|
|||
|
||||
/* Playback control functions */
|
||||
/*void load_file(string);*/
|
||||
void load(string);
|
||||
void load(string, bool);
|
||||
void play();
|
||||
void pause();
|
||||
void toggle_play();
|
||||
|
|
|
@ -43,7 +43,7 @@ namespace libsaria
|
|||
~Track();
|
||||
|
||||
void save(ofstream &);
|
||||
void play_now();
|
||||
void load(bool);
|
||||
|
||||
string &get_filepath();
|
||||
string get_title();
|
||||
|
|
|
@ -21,16 +21,14 @@ static bool change_state(GstState new_state)
|
|||
}
|
||||
}
|
||||
|
||||
void load_file(GstElement *playbin, string file)
|
||||
void load_file(GstElement *playbin, string file, GstState state)
|
||||
{
|
||||
GstState state = cur_state;
|
||||
|
||||
if (file == "" || !exists(file))
|
||||
return;
|
||||
|
||||
string uri = "file://" + file;
|
||||
println("Loading uri: " + uri);
|
||||
/* Preserve the current playback state */
|
||||
/* Set pipeline to the requested state */
|
||||
change_state(GST_STATE_READY);
|
||||
g_object_set(G_OBJECT(playbin), "uri", uri.c_str(), NULL);
|
||||
change_state(state);
|
||||
|
@ -68,9 +66,12 @@ namespace libsaria
|
|||
seek_to(0);
|
||||
}
|
||||
|
||||
void audio::load(string file)
|
||||
void audio::load(string file, bool play)
|
||||
{
|
||||
load_file(player, file);
|
||||
GstState state = GST_STATE_PLAYING;
|
||||
if (!play)
|
||||
state = GST_STATE_PAUSED;
|
||||
load_file(player, file, state);
|
||||
}
|
||||
|
||||
};
|
||||
|
|
|
@ -63,10 +63,8 @@ void restore_current()
|
|||
unsigned int l_id = libsaria::prefs::get("libsaria.current.library");
|
||||
unsigned int t_id = libsaria::prefs::get("libsaria.current.track");
|
||||
libsaria::Track *track = libsaria::library::lookup(l_id, t_id);
|
||||
if (track) {
|
||||
track->play_now();
|
||||
libsaria::audio::pause();
|
||||
}
|
||||
if (track)
|
||||
track->load(false);
|
||||
}
|
||||
|
||||
namespace libsaria
|
||||
|
|
|
@ -51,7 +51,7 @@ namespace libsaria
|
|||
println(message);
|
||||
return;
|
||||
}
|
||||
outside_track.play_now();
|
||||
outside_track.load(true);
|
||||
}
|
||||
|
||||
};
|
||||
|
|
|
@ -35,18 +35,22 @@ static void renumber_playlists()
|
|||
(*it)->renumber(n++);
|
||||
}
|
||||
|
||||
static void check_pause()
|
||||
static bool check_play()
|
||||
{
|
||||
bool ret = true;
|
||||
|
||||
switch(pause_type) {
|
||||
case PS_AFTER_N:
|
||||
if (pause_count == 0) {
|
||||
libsaria::audio::pause();
|
||||
ret = false;
|
||||
pause_type = PS_NONE;
|
||||
}
|
||||
pause_count--;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
namespace libsaria
|
||||
|
@ -74,9 +78,8 @@ namespace libsaria
|
|||
|
||||
track = plist->next();
|
||||
if (track) {
|
||||
track->play_now();
|
||||
track->load(check_play());
|
||||
list_recent_track(track);
|
||||
check_pause();
|
||||
}
|
||||
|
||||
if ((plist->get_size() == 0) && (plist->is_static() == false)) {
|
||||
|
@ -92,7 +95,7 @@ namespace libsaria
|
|||
{
|
||||
Track *track = recent_plist.next();
|
||||
if (track)
|
||||
track->play_now();
|
||||
track->load(true);
|
||||
}
|
||||
|
||||
void set_on_new_playlist(void (*func)(Playlist *))
|
||||
|
|
|
@ -138,16 +138,16 @@ namespace libsaria
|
|||
{
|
||||
}
|
||||
|
||||
void Track::play_now()
|
||||
void Track::load(bool play)
|
||||
{
|
||||
println("Playing: " + title + " by " + artist);
|
||||
println("Loading: " + title + " by " + artist);
|
||||
if (path) {
|
||||
prefs::set("libsaria.current.library", path->id);
|
||||
prefs::set("libsaria.current.track", id);
|
||||
}
|
||||
audio::load(filepath);
|
||||
audio::play();
|
||||
|
||||
cur = this;
|
||||
audio::load(filepath, play);
|
||||
}
|
||||
|
||||
Track *current_track()
|
||||
|
|
|
@ -43,7 +43,7 @@ static void track_selected(GtkWidget *treeview, GtkTreePath *path,
|
|||
gtk_tree_model_get_iter(model, &iter, path);
|
||||
gtk_tree_model_get(model, &iter, 0, &track, -1);
|
||||
|
||||
track->play_now();
|
||||
track->load(true);
|
||||
}
|
||||
|
||||
static gboolean do_filter(GtkTreeModel *model, GtkTreeIter *iter, gpointer data)
|
||||
|
|
Loading…
Reference in New Issue