Changeset 2631
- Timestamp:
- 08/04/07 14:50:34 (6 years ago)
- Location:
- trunk/src/target/OM-2007.2/applications/openmoko-mediaplayer/src
- Files:
-
- 9 edited
-
Makefile.am (modified) (1 diff)
-
main.c (modified) (5 diffs)
-
main.h (modified) (1 diff)
-
mainwin.c (modified) (12 diffs)
-
mainwin.h (modified) (2 diffs)
-
playback.c (modified) (9 diffs)
-
playback.h (modified) (2 diffs)
-
playlist.c (modified) (10 diffs)
-
playlist.h (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/target/OM-2007.2/applications/openmoko-mediaplayer/src/Makefile.am
r2613 r2631 18 18 $(OMP_DEFINES) \ 19 19 -I$(top_srcdir) \ 20 -I$(top_srcdir)/intl 20 -I$(top_srcdir)/intl\ 21 -g -DDEBUG 21 22 22 23 INCLUDES = $(openmoko_mediaplayer_CFLAGS) -
trunk/src/target/OM-2007.2/applications/openmoko-mediaplayer/src/main.c
r2613 r2631 141 141 omp_config_restore_state() 142 142 { 143 #ifdef DEBUG 144 g_print("Loading playlist and restoring playback state\n"); 145 #endif 146 143 147 // This mustn't be called more than once 144 148 g_assert(omp_config == NULL); … … 159 163 if (!omp_playlist_set_current_track(omp_config->playlist_position)) 160 164 { 161 // Reset playlist state as it must have been modified since it was last loaded165 // Reset playlist state as playlist must have been modified since it was last loaded 162 166 omp_config->playlist_position = 0; 163 167 omp_config->track_position = 0; 164 } 168 omp_playlist_set_current_track(0); 169 } 165 170 166 171 // Feed the track entity to the playback engine to obtain track information … … 363 368 signal(SIGUSR1, handler_sigusr1); 364 369 365 // Load config and restore playback state366 omp_config_restore_state();367 368 370 // Initialize playback, playlist and UI handling 369 371 omp_main_window_create(); … … 371 373 omp_playlist_init(); 372 374 omp_main_connect_signals(); 373 omp_ main_update_track_info();375 omp_config_restore_state(); 374 376 omp_main_window_show(); 375 377 … … 385 387 omp_playlist_free(); 386 388 gst_deinit(); 389 g_free(ui_image_path); 387 390 388 391 #ifdef DEBUG_MEM_PROFILE -
trunk/src/target/OM-2007.2/applications/openmoko-mediaplayer/src/main.h
r2613 r2631 53 53 gchar playlist_file[256]; ///< Path and file name of current (=last used) playlist 54 54 gint playlist_position; ///< Position within the playlist 55 g inttrack_position; ///< Position to resume playback from within the last played track55 glong track_position; ///< Position to resume playback from within the last played track 56 56 }; 57 57 -
trunk/src/target/OM-2007.2/applications/openmoko-mediaplayer/src/mainwin.c
r2613 r2631 60 60 GtkWidget *omp_main_window = NULL; 61 61 62 gboolean omp_main_time_slider_can_update = TRUE; 63 gboolean omp_main_time_slider_was_dragged = FALSE; 62 64 63 65 … … 68 70 omp_application_terminate() 69 71 { 70 // Free resources71 g_free(ui_image_path);72 73 72 // Tell GTK to leave the message loop 74 73 gtk_main_quit(); … … 191 190 } 192 191 192 /** 193 * Gets called when the time slider's value got changed (yes, that means it gets called every second, too) 194 */ 195 void 196 omp_main_time_slider_changed(GtkRange *range, gpointer data) 197 { 198 if (omp_main_time_slider_was_dragged) 199 { 200 omp_main_time_slider_was_dragged = FALSE; 201 202 // Set new position and resume playback that was paused when dragging started 203 omp_playback_set_track_position(gtk_range_get_value(GTK_RANGE(range))); 204 205 // Update UI right away 206 gtk_range_set_value(GTK_RANGE(main_widgets.time_hscale), omp_playback_get_track_position()); 207 } 208 } 209 210 /** 211 * Gets called when the user starts dragging the time slider 212 */ 213 gboolean 214 omp_main_time_slider_drag_start(GtkWidget *widget, GdkEventButton *event, gpointer user_data) 215 { 216 while (gtk_events_pending()) gtk_main_iteration(); 217 218 // Prevent UI callbacks from messing with the slider position 219 omp_main_time_slider_can_update = FALSE; 220 } 221 222 /** 223 * Gets called when the user stops dragging the time slider 224 */ 225 gboolean 226 omp_main_time_slider_drag_stop(GtkWidget *widget, GdkEventButton *event, gpointer user_data) 227 { 228 while (gtk_events_pending()) gtk_main_iteration(); 229 230 // Allow UI callbacks to alter the the slider position again 231 omp_main_time_slider_can_update = TRUE; 232 233 // Notify the slider change callback that this time we indeed want to change position 234 omp_main_time_slider_was_dragged = TRUE; 235 } 236 193 237 void 194 238 omp_shuffle_button_callback(GtkWidget* widget, gpointer data) … … 226 270 227 271 /** 272 * Event handler for the Fast Forward button 273 */ 274 void 275 omp_main_button_fast_forward_callback() 276 { 277 // Set new position and resume playback that was paused when dragging started 278 omp_playback_set_track_position(omp_playback_get_track_position()+BUTTON_SEEK_DISTANCE); 279 280 // Update UI right away 281 gtk_range_set_value(GTK_RANGE(main_widgets.time_hscale), omp_playback_get_track_position()); 282 } 283 284 /** 285 * Event handler for the Rewind button 286 */ 287 void 288 omp_main_button_rewind_callback() 289 { 290 // Set new position and resume playback that was paused when dragging started 291 omp_playback_set_track_position(omp_playback_get_track_position()-BUTTON_SEEK_DISTANCE); 292 293 // Update UI right away 294 gtk_range_set_value(GTK_RANGE(main_widgets.time_hscale), omp_playback_get_track_position()); 295 } 296 297 /** 228 298 * Event handler for the Play/Pause button 229 * @todo State change, etc299 * @todo Pixmap change 230 300 */ 231 301 void 232 302 omp_main_button_play_pause_callback() 233 303 { 234 omp_playback_play(); 304 if (omp_playback_get_state() != OMP_PLAYBACK_STATE_PLAYING) 305 { 306 omp_playback_play(); 307 308 } else { 309 310 omp_playback_pause(); 311 } 235 312 } 236 313 … … 283 360 image = gtk_image_new_from_icon_name(image_name, 36); 284 361 gtk_container_add(GTK_CONTAINER(button), GTK_WIDGET(image)); 285 g_object_unref(image);286 362 287 363 return button; … … 389 465 GTK_WIDGET_UNSET_FLAGS(GTK_WIDGET(main_widgets.time_hscale), GTK_CAN_FOCUS); 390 466 gtk_widget_set_size_request(GTK_WIDGET(main_widgets.time_hscale), 338, 35); 467 gtk_range_set_update_policy(GTK_RANGE(main_widgets.time_hscale), GTK_UPDATE_DISCONTINUOUS); 391 468 gtk_range_set_value(GTK_RANGE(main_widgets.time_hscale), 0.0); 392 // g_signal_connect(G_OBJECT(time_hscale), "change_value", 393 // G_CALLBACK(omp_main_set_time), NULL); 469 g_signal_connect(G_OBJECT(main_widgets.time_hscale), "value_changed", G_CALLBACK(omp_main_time_slider_changed), NULL); 470 g_signal_connect(G_OBJECT(main_widgets.time_hscale), "button-press-event", G_CALLBACK(omp_main_time_slider_drag_start), NULL); 471 g_signal_connect(G_OBJECT(main_widgets.time_hscale), "button-release-event", G_CALLBACK(omp_main_time_slider_drag_stop), NULL); 394 472 gtk_container_add(GTK_CONTAINER(alignment), GTK_WIDGET(main_widgets.time_hscale)); 395 473 … … 484 562 485 563 // Rewind button 486 button = omp_button_create("gtk-media-rewind-ltr", NULL);564 button = omp_button_create("gtk-media-rewind-ltr", G_CALLBACK(omp_main_button_rewind_callback)); 487 565 gtk_box_pack_start(GTK_BOX(controls_hbox), button, TRUE, TRUE, 0); 488 566 gtk_box_set_child_packing(GTK_BOX(controls_hbox), GTK_WIDGET(button), FALSE, FALSE, 0, GTK_PACK_START); … … 494 572 495 573 // Fast Forward button 496 button = omp_button_create("gtk-media-forward-ltr", NULL);574 button = omp_button_create("gtk-media-forward-ltr", G_CALLBACK(omp_main_button_fast_forward_callback)); 497 575 gtk_box_pack_start(GTK_BOX(controls_hbox), button, TRUE, TRUE, 0); 498 576 gtk_box_set_child_packing(GTK_BOX(controls_hbox), GTK_WIDGET(button), FALSE, FALSE, 0, GTK_PACK_START); … … 537 615 gtk_widget_show_all(GTK_WIDGET(bg_muxer)); 538 616 617 539 618 return; 540 619 } … … 548 627 omp_main_connect_signals() 549 628 { 550 g_signal_connect(G_OBJECT(omp_main_window), OMP_EVENT_P REV_TRACK, G_CALLBACK(omp_main_update_track_info), NULL);551 g_signal_connect(G_OBJECT(omp_main_window), OMP_EVENT_ NEXT_TRACK, G_CALLBACK(omp_main_update_track_info), NULL);552 } 553 629 g_signal_connect(G_OBJECT(omp_main_window), OMP_EVENT_PLAYLIST_TRACK_CHANGED, G_CALLBACK(omp_main_update_track_change), NULL); 630 g_signal_connect(G_OBJECT(omp_main_window), OMP_EVENT_PLAYBACK_STATUS_CHANGED, G_CALLBACK(omp_main_update_track_change), NULL); 631 g_signal_connect(G_OBJECT(omp_main_window), OMP_EVENT_PLAYBACK_POSITION_CHANGED, G_CALLBACK(omp_main_update_track_position), NULL); 632 } 554 633 555 634 /** 556 635 * Evaluates current track information and updates the config/UI if necessary 557 */ 558 void 559 omp_main_update_track_info() 636 * @note This function only checks elements that don't change too often - for the rest we have specialized functions below 637 */ 638 void 639 omp_main_update_track_change() 560 640 { 561 641 static gint old_track_count = 0; 562 642 static gint old_track_id = 0; 563 643 static gulong old_track_length = 0; 644 645 gulong track_length, track_position; 564 646 gchar *text; 565 647 … … 573 655 omp_config_update(); 574 656 575 // Update UI657 // Update label 576 658 text = g_strdup_printf(WIDGET_CAPTION_TRACK_NUM, omp_playlist_current_track_id+1, omp_playlist_track_count); 577 659 gtk_label_set_text(GTK_LABEL(main_widgets.track_number_label), text); … … 579 661 } 580 662 581 582 } 583 663 // Got a track length change? 664 track_length = omp_playback_get_track_length(); 665 666 if (track_length != old_track_length) 667 { 668 old_track_length = track_length; 669 track_position = omp_playback_get_track_position(); 670 671 // Set new time slider increments 672 gtk_range_set_increments(GTK_RANGE(main_widgets.time_hscale), track_length/10, track_length/10); 673 674 // Update label and slider 675 text = g_strdup_printf(WIDGET_CAPTION_TRACK_TIME, 676 track_position / 60, track_position % 60, 677 track_length / 60, track_length % 60); 678 gtk_label_set_text(GTK_LABEL(main_widgets.time_label), text); 679 g_free(text); 680 681 if (omp_main_time_slider_can_update) 682 { 683 gtk_range_set_range(GTK_RANGE(main_widgets.time_hscale), 0, track_length ? track_length : 1); 684 gtk_range_set_value(GTK_RANGE(main_widgets.time_hscale), track_position); 685 } 686 } 687 } 688 689 /** 690 * Updates the UI if the playback position changed 691 */ 692 void 693 omp_main_update_track_position() 694 { 695 static gulong old_track_position = 0; 696 697 gulong track_position, track_length; 698 gchar *text; 699 700 // Got a track length change? 701 track_position = omp_playback_get_track_position(); 702 { 703 old_track_position = track_position; 704 track_length = omp_playback_get_track_length(); 705 706 // Update UI 707 text = g_strdup_printf(WIDGET_CAPTION_TRACK_TIME, 708 track_position / 60, track_position % 60, 709 track_length / 60, track_length % 60); 710 gtk_label_set_text(GTK_LABEL(main_widgets.time_label), text); 711 g_free(text); 712 713 if (omp_main_time_slider_can_update) 714 { 715 gtk_range_set_range(GTK_RANGE(main_widgets.time_hscale), 0, track_length ? track_length : 1); 716 gtk_range_set_value(GTK_RANGE(main_widgets.time_hscale), track_position); 717 } 718 } 719 720 } 721 -
trunk/src/target/OM-2007.2/applications/openmoko-mediaplayer/src/mainwin.h
r2613 r2631 34 34 #define WIDGET_CAPTION_VOLUME "%d%%" 35 35 36 // Determines how many seconds the engine will seek if the FFWD/REW buttons are clicked 37 #define BUTTON_SEEK_DISTANCE 10 38 36 39 extern GtkWidget *omp_main_window; 37 40 … … 43 46 void omp_main_connect_signals(); 44 47 45 void omp_main_update_track_info(); 48 void omp_main_update_track_change(); 49 void omp_main_update_track_position(); 46 50 47 51 #endif -
trunk/src/target/OM-2007.2/applications/openmoko-mediaplayer/src/playback.c
r2613 r2631 31 31 32 32 GstElement *omp_gst_playbin = NULL; 33 34 33 guint omp_playback_ui_timeout = 0; 34 gboolean omp_playback_ui_timeout_halted; 35 35 36 36 /** … … 49 49 50 50 // Create the signals we'll emit 51 g_signal_new(OMP_EVENT_PLAYBACK_EOS, G_TYPE_OBJECT, 0, 0, 0, NULL, g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0, NULL); 51 g_signal_new(OMP_EVENT_PLAYBACK_EOS, G_TYPE_OBJECT, 0, 0, 0, NULL, g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0, NULL); 52 g_signal_new(OMP_EVENT_PLAYBACK_STATUS_CHANGED, G_TYPE_OBJECT, 0, 0, 0, NULL, g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0, NULL); 53 g_signal_new(OMP_EVENT_PLAYBACK_POSITION_CHANGED, G_TYPE_OBJECT, 0, 0, 0, NULL, g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0, NULL); 52 54 53 55 // Set up gstreamer pipe and bins … … 82 84 /** 83 85 * Attempts to load a track from an URI 86 * @return TRUE if successful, FALSE if failed 84 87 */ 85 88 gboolean … … 92 95 } 93 96 94 // DEBUG 95 g_printf("Loading %s\n", uri); 97 #ifdef DEBUG 98 g_printf("Loading track: %s\n", uri); 99 #endif 96 100 97 101 gst_element_set_state(omp_gst_playbin, GST_STATE_NULL); 98 102 g_object_set(G_OBJECT(omp_gst_playbin), "uri", uri, NULL); 99 103 gst_element_set_state(omp_gst_playbin, GST_STATE_PAUSED); 104 105 return (gst_element_set_state(omp_gst_playbin, GST_STATE_PAUSED) != GST_STATE_CHANGE_FAILURE); 106 } 107 108 /** 109 * This callback gets called at least once per second if a track is playing 110 */ 111 static gboolean 112 omp_playback_ui_timeout_callback(gpointer data) 113 { 114 g_signal_emit_by_name(G_OBJECT(omp_main_window), OMP_EVENT_PLAYBACK_POSITION_CHANGED); 115 116 if (omp_playback_ui_timeout_halted) 117 { 118 // Reset the timeout ID so we can prevent race conditions 119 omp_playback_ui_timeout = 0; 120 return FALSE; 121 } 122 123 return TRUE; 100 124 } 101 125 … … 106 130 omp_playback_play() 107 131 { 108 // DEBUG 109 g_print("Starting playback\n"); 110 132 #ifdef DEBUG 133 g_print("Starting playback\n"); 134 #endif 135 136 // Set state 111 137 gst_element_set_state(omp_gst_playbin, GST_STATE_PLAYING); 138 g_signal_emit_by_name(G_OBJECT(omp_main_window), OMP_EVENT_PLAYBACK_STATUS_CHANGED); 139 140 // Add timer to update UI if necessary 141 // If the halt flag was set but the callback didn't run yet then we 142 // don't want to add another callback since we would have two then 143 omp_playback_ui_timeout_halted = FALSE; 144 145 if (!omp_playback_ui_timeout) 146 { 147 omp_playback_ui_timeout = g_timeout_add(PLAYBACK_UI_UPDATE_INTERVAL, omp_playback_ui_timeout_callback, NULL); 148 } 149 } 150 151 /** 152 * Suspends playback of the current stream 153 */ 154 void 155 omp_playback_pause() 156 { 157 #ifdef DEBUG 158 g_print("Suspending playback\n"); 159 #endif 160 161 // Set state 162 gst_element_set_state(omp_gst_playbin, GST_STATE_PAUSED); 163 g_signal_emit_by_name(G_OBJECT(omp_main_window), OMP_EVENT_PLAYBACK_STATUS_CHANGED); 164 165 // Stop timer 166 omp_playback_ui_timeout_halted = TRUE; 112 167 } 113 168 114 169 /** 115 170 * Returns the current state the playback engine is in 171 * @todo Don't use system clock, might be out-of-sync with playbin clock? 116 172 */ 117 173 gint … … 119 175 { 120 176 GstState state; 121 Gst SystemClock *system_clock;177 GstClock *clock; 122 178 123 179 // Poll state with an immediate timeout 124 system_clock = gst_system_clock_obtain();125 gst_element_get_state(GST_ OBJECT(omp_gst_playbin), &state, NULL, gst_clock_get_time(system_clock));126 gst_object_unref( system_clock);127 128 // The NULL element state is no different from READYfor more abstract layers129 if ( state == GST_STATE_NULL)130 { 131 state = GST_STATE_ READY;180 clock = gst_system_clock_obtain(); 181 gst_element_get_state(GST_ELEMENT(omp_gst_playbin), &state, NULL, gst_clock_get_time(clock)); 182 gst_object_unref(clock); 183 184 // The NULL and READY element states are no different from PAUSED for more abstract layers 185 if ( (state == GST_STATE_NULL) || (state == GST_STATE_READY) ) 186 { 187 state = GST_STATE_PAUSED; 132 188 } 133 189 134 190 return (gint)state; 191 } 192 193 /** 194 * Returns the number of seconds that the track has been playing so far 195 */ 196 gulong 197 omp_playback_get_track_position() 198 { 199 GstFormat format = GST_FORMAT_TIME; 200 gint64 position; 201 202 if (!omp_gst_playbin) 203 { 204 return 0; 205 } 206 207 // Return 0 if function returns FALSE, position otherwise 208 return (gst_element_query_position(omp_gst_playbin, &format, &position)) ? (position/GST_SECOND) : 0; 209 } 210 211 /** 212 * Sets the playback position of the currently loaded track 213 */ 214 void 215 omp_playback_set_track_position(glong position) 216 { 217 if (!omp_gst_playbin) 218 { 219 return; 220 } 221 222 gst_element_seek_simple(GST_ELEMENT(omp_gst_playbin), 223 GST_FORMAT_TIME, 224 GST_SEEK_FLAG_FLUSH | GST_SEEK_FLAG_ACCURATE, 225 position*GST_SECOND); 226 227 g_signal_emit_by_name(G_OBJECT(omp_main_window), OMP_EVENT_PLAYBACK_POSITION_CHANGED); 228 } 229 230 /** 231 * Returns the current track's playing length 232 */ 233 gulong 234 omp_playback_get_track_length() 235 { 236 GstFormat format = GST_FORMAT_TIME; 237 gint64 length; 238 239 if (!omp_gst_playbin) 240 { 241 return 0; 242 } 243 244 // Return 0 if function returns FALSE, track length otherwise 245 return (gst_element_query_duration(omp_gst_playbin, &format, &length)) ? (length/GST_SECOND) : 0; 135 246 } 136 247 … … 141 252 omp_gst_message_eos(GstBus *bus, GstMessage *message, gpointer data) 142 253 { 143 // DEBUG 144 g_printf("End of stream reached.\n"); 145 146 gst_element_set_state(omp_gst_playbin, GST_STATE_NULL); 254 #ifdef DEBUG 255 g_printf("End of stream reached.\n"); 256 #endif 257 258 // Reset playback engine 259 gst_element_set_state(omp_gst_playbin, GST_STATE_READY); 260 omp_playback_set_track_position(0); 261 147 262 g_signal_emit_by_name(G_OBJECT(omp_main_window), OMP_EVENT_PLAYBACK_EOS); 148 263 … … 158 273 GError *error; 159 274 160 gst_message_parse_error(message, &error, NULL); 161 g_printerr("gstreamer error: %s\n", error->message); 162 g_error_free(error); 275 #ifdef DEBUG 276 gst_message_parse_error(message, &error, NULL); 277 g_printerr("gstreamer error: %s\n", error->message); 278 gst_message_unref(error); 279 g_error_free(error); 280 #endif 163 281 164 282 return TRUE; … … 173 291 GError *error; 174 292 175 gst_message_parse_error(message, &error, NULL); 176 g_printerr("gstreamer warning: %s\n", error->message); 177 g_error_free(error); 293 #ifdef DEBUG 294 gst_message_parse_warning(message, &error, NULL); 295 g_printerr("gstreamer warning: %s\n", error->message); 296 gst_message_unref(error); 297 g_error_free(error); 298 #endif 178 299 179 300 return TRUE; 180 301 } 181 -
trunk/src/target/OM-2007.2/applications/openmoko-mediaplayer/src/playback.h
r2613 r2631 31 31 32 32 #define OMP_EVENT_PLAYBACK_EOS "playback_end_of_stream" 33 #define OMP_EVENT_PLAYBACK_STATUS_CHANGED "playback_status_change" 34 #define OMP_EVENT_PLAYBACK_POSITION_CHANGED "playback_position_change" 33 35 34 36 // Player states masking the gstreamer states so we can be more abstract 35 #define OMP_PLAYBACK_STATE_READY GST_STATE_READY36 37 #define OMP_PLAYBACK_STATE_PAUSED GST_STATE_PAUSED 37 38 #define OMP_PLAYBACK_STATE_PLAYING GST_STATE_PLAYING 38 39 40 // The UI will be updated at this interval when a track is playing (in ms) 41 #define PLAYBACK_UI_UPDATE_INTERVAL 1000 39 42 40 43 void omp_playback_init(); … … 44 47 45 48 void omp_playback_play(); 49 void omp_playback_pause(); 46 50 gint omp_playback_get_state(); 51 gulong omp_playback_get_track_position(); 52 void omp_playback_set_track_position(glong position); 53 gulong omp_playback_get_track_length(); 47 54 48 55 static gboolean omp_gst_message_eos(GstBus *bus, GstMessage *message, gpointer data); -
trunk/src/target/OM-2007.2/applications/openmoko-mediaplayer/src/playlist.c
r2613 r2631 63 63 64 64 // Create the signals we emit: no params, no return value 65 g_signal_new(OMP_EVENT_PREV_TRACK, G_TYPE_OBJECT, 0, 0, 0, NULL, g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0, NULL); 66 g_signal_new(OMP_EVENT_NEXT_TRACK, G_TYPE_OBJECT, 0, 0, 0, NULL, g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0, NULL); 65 g_signal_new(OMP_EVENT_PLAYLIST_TRACK_CHANGED, G_TYPE_OBJECT, 0, 0, 0, NULL, g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0, NULL); 67 66 } 68 67 … … 94 93 omp_playlist_load(gchar *playlist_file) 95 94 { 95 // Free the track history's memory by deleting the first element until the list is empty 96 while (omp_track_history) 97 { 98 g_free(omp_track_history->data); 99 omp_track_history = g_slist_delete_link(omp_track_history, omp_track_history); 100 } 101 102 // Let XSPF clean up, too 96 103 if (omp_playlist) 97 104 { … … 125 132 gint track_num = 0; 126 133 127 // DEBUG 128 g_printf("Setting current track to #%d\n", playlist_pos); 134 #ifdef DEBUG 135 g_printf("Setting current track to #%d\n", playlist_pos); 136 #endif 129 137 130 138 if (!omp_playlist) … … 147 155 { 148 156 omp_playlist_track_count = track_num; 157 158 // Emit signal to update UI and the like 159 g_signal_emit_by_name(G_OBJECT(omp_main_window), OMP_EVENT_PLAYLIST_TRACK_CHANGED); 149 160 } 150 161 … … 162 173 struct omp_track_history_entry *history_entry; 163 174 struct spiff_track *track; 175 gboolean was_playing; 164 176 gboolean is_new_track = FALSE; 165 177 … … 168 180 return; 169 181 } 182 183 // If track playing time is >= 10 seconds we just jump back to the beginning of the track 184 if (omp_playback_get_track_position() >= 10) 185 { 186 omp_playback_set_track_position(0); 187 return TRUE; 188 } 189 190 // Get player state so we can continue playback if necessary 191 was_playing = (omp_playback_get_state() == OMP_PLAYBACK_STATE_PLAYING); 192 193 try_again: 194 195 #ifdef DEBUG 196 if (omp_track_history) 197 { 198 GSList *list; 199 g_printf("--- Track History:\n"); 200 list = omp_track_history; 201 while (list) 202 { 203 history_entry = list->data; 204 g_printf("- %s\n", history_entry->track->locations->value); 205 list = g_slist_next(list); 206 } 207 g_printf("---\n"); 208 } 209 #endif 170 210 171 211 // Do we have tracks in the history to go back to? … … 198 238 if (track->next) 199 239 { 200 omp_playlist_current_track = track;240 omp_playlist_current_track = track; 201 241 omp_playlist_current_track_id--; 202 242 } … … 207 247 { 208 248 // Emit signal to update UI and the like 209 g_signal_emit_by_name(G_OBJECT(omp_main_window), OMP_EVENT_PREV_TRACK); 249 g_signal_emit_by_name(G_OBJECT(omp_main_window), OMP_EVENT_PLAYLIST_TRACK_CHANGED); 250 251 // Load track and start playing if needed 252 if (omp_playlist_load_current_track()) 253 { 254 if (was_playing) omp_playback_play(); 255 256 } else { 257 258 // Uh-oh, track failed to load - let's find another one, shall we? 259 is_new_track = FALSE; 260 goto try_again; 261 } 210 262 } 211 263 … … 238 290 // Prepare the history entry - if we don't need it we'll just free it again 239 291 history_entry = g_new(struct omp_track_history_entry, 1); 240 history_entry->track = omp_playlist_current_track;241 history_entry->track_id = omp_playlist_current_track_id;292 history_entry->track = omp_playlist_current_track; 293 history_entry->track_id = omp_playlist_current_track_id; 242 294 243 295 // Do we have a track to play? … … 257 309 258 310 // Emit signal to update UI and the like 259 g_signal_emit_by_name(G_OBJECT(omp_main_window), OMP_EVENT_ NEXT_TRACK);311 g_signal_emit_by_name(G_OBJECT(omp_main_window), OMP_EVENT_PLAYLIST_TRACK_CHANGED); 260 312 261 313 // Load track and start playing if needed -
trunk/src/target/OM-2007.2/applications/openmoko-mediaplayer/src/playlist.h
r2613 r2631 30 30 #include <spiff/spiff_c.h> 31 31 32 #define OMP_EVENT_PREV_TRACK "prev_track" 33 #define OMP_EVENT_NEXT_TRACK "next_track" 34 35 36 extern struct _omp_playlist_events omp_playlist_events; 37 32 #define OMP_EVENT_PLAYLIST_TRACK_CHANGED "playlist_track_changed" 38 33 39 34 extern struct spiff_list *omp_playlist;
Note: See TracChangeset
for help on using the changeset viewer.
