- int i_input;
- DBusMessage* p_dbus_msg = NULL;
- DBusMessageIter dbus_args;
- DBusPendingCall* p_dbus_pending = NULL;
- dbus_bool_t b_play;
-
- msg_Warn( p_libvlc, "Another Media Player is running. Exiting");
-
- for( i_input = vlc_optind; i_input < i_argc;i_input++ )
- {
- /* Skip input options, we can't pass them through D-Bus */
- if( ppsz_argv[i_input][0] == ':' )
- {
- msg_Warn( p_libvlc, "Ignoring option %s",
- ppsz_argv[i_input] );
- continue;
- }
-
- /* We need to resolve relative paths in this instance */
- char *psz_mrl;
- if( strstr( psz_mrl, "://" ) )
- psz_mrl = strdup( ppsz_argv[i_input] );
- else
- psz_mrl = vlc_path2uri( ppsz_argv[i_input], NULL );
- const char *psz_after_track = MPRIS_APPEND;
-
- if( psz_mrl == NULL )
- continue;
- msg_Dbg( p_libvlc, "Adds %s to the running Media Player",
- psz_mrl );
-
- p_dbus_msg = dbus_message_new_method_call(
- MPRIS_BUS_NAME, MPRIS_OBJECT_PATH,
- MPRIS_TRACKLIST_INTERFACE, "AddTrack" );
-
- if ( NULL == p_dbus_msg )
- {
- msg_Err( p_libvlc, "D-Bus problem" );
- free( psz_mrl );
- system_End( );
- exit( 1 );
- }
-
- /* append MRLs */
- dbus_message_iter_init_append( p_dbus_msg, &dbus_args );
- if ( !dbus_message_iter_append_basic( &dbus_args,
- DBUS_TYPE_STRING, &psz_mrl ) )
- {
- dbus_message_unref( p_dbus_msg );
- free( psz_mrl );
- system_End( );
- exit( 1 );
- }
- free( psz_mrl );
-
- if( !dbus_message_iter_append_basic( &dbus_args,
- DBUS_TYPE_OBJECT_PATH, &psz_after_track ) )
- {
- dbus_message_unref( p_dbus_msg );
- system_End( );
- exit( 1 );
- }
-
- b_play = TRUE;
- if( var_InheritBool( p_libvlc, "playlist-enqueue" ) )
- b_play = FALSE;
-
- if ( !dbus_message_iter_append_basic( &dbus_args,
- DBUS_TYPE_BOOLEAN, &b_play ) )
- {
- dbus_message_unref( p_dbus_msg );
- system_End( );
- exit( 1 );
- }
-
- /* send message and get a handle for a reply */
- if ( !dbus_connection_send_with_reply ( p_conn,
- p_dbus_msg, &p_dbus_pending, -1 ) )
- {
- msg_Err( p_libvlc, "D-Bus problem" );
- dbus_message_unref( p_dbus_msg );
- system_End( );
- exit( 1 );
- }
-
- if ( NULL == p_dbus_pending )
- {
- msg_Err( p_libvlc, "D-Bus problem" );
- dbus_message_unref( p_dbus_msg );
- system_End( );
- exit( 1 );
- }
- dbus_connection_flush( p_conn );
- dbus_message_unref( p_dbus_msg );
- /* block until we receive a reply */
- dbus_pending_call_block( p_dbus_pending );
- dbus_pending_call_unref( p_dbus_pending );
- } /* processes all command line MRLs */
-
- /* bye bye */
- system_End( );
- exit( 0 );