Exemple #1
0
QVariant PlayFilesModel::playItem(int indx) const
{
    if(indx>=m_playList.size())
    {
        return QVariant::fromValue(PlayItem());
    }

    return QVariant::fromValue(m_playList[indx]);
}
void OverviewPlaylistWidget::StartPlaylist()
{
	if (!mIsPlayed)
	{
		if (mLwFiles->count() == 0)
			AddEntryDialog();

		PlayItem(mLwFiles->item(mCurrentFileId));
	}
}
Exemple #3
0
static bool Next( playlist_t *p_playlist )
{
    playlist_item_t *p_item = NextItem( p_playlist );
    if( p_item == NULL )
        return false;

    msg_Dbg( p_playlist, "starting playback of new item" );
    ResyncCurrentIndex( p_playlist, p_item );
    return PlayItem( p_playlist, p_item );
}
static void LoopRequest( playlist_t *p_playlist )
{
    playlist_private_t *p_sys = pl_priv(p_playlist);
    assert( !p_sys->p_input );

    /* No input. Several cases
     *  - No request, running status -> start new item
     *  - No request, stopped status -> collect garbage
     *  - Request, running requested -> start new item
     *  - Request, stopped requested -> collect garbage
    */
    const int i_status = p_sys->request.b_request ?
                         p_sys->request.i_status : p_sys->status.i_status;

    if( i_status == PLAYLIST_STOPPED || !vlc_object_alive( p_playlist ) )
    {
        p_sys->status.i_status = PLAYLIST_STOPPED;

        if( p_sys->p_input_resource &&
            input_resource_HasVout( p_sys->p_input_resource ) )
        {
            /* XXX We can unlock if we don't issue the wait as we will be
             * call again without anything else done between the calls */
            PL_UNLOCK;

            /* input_resource_t must be manipulated without playlist lock */
            input_resource_TerminateVout( p_sys->p_input_resource );

            PL_LOCK;
        }
        else
        {
            if( vlc_object_alive( p_playlist ) )
                vlc_cond_wait( &p_sys->signal, &p_sys->lock );
        }
        return;
    }

    playlist_item_t *p_item = NextItem( p_playlist );
    if( p_item )
    {
        msg_Dbg( p_playlist, "starting playback of the new playlist item" );
        PlayItem( p_playlist, p_item );
        return;
    }

    msg_Dbg( p_playlist, "nothing to play" );
    p_sys->status.i_status = PLAYLIST_STOPPED;

    if( var_GetBool( p_playlist, "play-and-exit" ) )
    {
        msg_Info( p_playlist, "end of playlist, exiting" );
        libvlc_Quit( p_playlist->p_libvlc );
    }
}
Exemple #5
0
void PlaylistView::keyPressEvent(QKeyEvent* event) {
  if (!model() || state() == QAbstractItemView::EditingState) {
    QTreeView::keyPressEvent(event);
  } else if (event == QKeySequence::Delete) {
    RemoveSelected();
    event->accept();
#ifdef Q_OS_DARWIN
  } else if (event->key() == Qt::Key_Backspace) {
    RemoveSelected();
    event->accept();
#endif
  } else if (event == QKeySequence::Copy) {
    CopyCurrentSongToClipboard();
  } else if (event->key() == Qt::Key_Enter || event->key() == Qt::Key_Return) {
    if (currentIndex().isValid()) emit PlayItem(currentIndex());
    event->accept();
  } else if (event->modifiers() != Qt::ControlModifier  // Ctrl+Space selects
                                                        // the item
             &&
             event->key() == Qt::Key_Space) {
    emit PlayPause();
    event->accept();
  } else if (event->key() == Qt::Key_Left) {
    emit SeekTrack(-1);
    event->accept();
  } else if (event->key() == Qt::Key_Right) {
    emit SeekTrack(1);
    event->accept();
  } else if (event->modifiers() ==
                 Qt::NoModifier  // No modifier keys currently pressed...
                 // ... and key pressed is something related to text
             &&
             ((event->key() >= Qt::Key_A && event->key() <= Qt::Key_Z) ||
              event->key() == Qt::Key_Backspace ||
              event->key() == Qt::Key_Escape)) {
    emit FocusOnFilterSignal(event);
    event->accept();
  } else {
    QTreeView::keyPressEvent(event);
  }
}
static void LoopRequest( playlist_t *p_playlist, int i_status )
{
    playlist_private_t *p_sys = pl_priv(p_playlist);
    assert( !p_sys->p_input );

    /* No input. Several cases
     *  - No request, running status -> start new item
     *  - No request, stopped status -> collect garbage
     *  - Request, running requested -> start new item
     *  - Request, stopped requested -> collect garbage
    */
    if( i_status == PLAYLIST_STOPPED )
    {
        p_sys->status.i_status = PLAYLIST_STOPPED;
        vlc_cond_wait( &p_sys->signal, &p_sys->lock );
        return;
    }

    playlist_item_t *p_item = NextItem( p_playlist );
    if( p_item )
    {
        msg_Dbg( p_playlist, "starting playback of the new playlist item" );
        ResyncCurrentIndex( p_playlist, p_item );
        PlayItem( p_playlist, p_item );
        return;
    }

    msg_Dbg( p_playlist, "nothing to play" );
    p_sys->status.i_status = PLAYLIST_STOPPED;

    if( var_InheritBool( p_playlist, "play-and-exit" ) )
    {
        msg_Info( p_playlist, "end of playlist, exiting" );
        libvlc_Quit( p_playlist->p_libvlc );
    }
}
Exemple #7
0
/*****************************************************************************
 * RunThread: main playlist thread
 *****************************************************************************/
static void RunThread ( playlist_t *p_playlist )
{
    vlc_object_t *p_obj;
    vlc_value_t val;

    mtime_t    i_vout_destroyed_date = 0;
    mtime_t    i_sout_destroyed_date = 0;

    playlist_item_t *p_autodelete_item = 0;

    /* Tell above that we're ready */
    vlc_thread_ready( p_playlist );

    while( !p_playlist->b_die )
    {
        vlc_mutex_lock( &p_playlist->object_lock );

        /* If there is an input, check that it doesn't need to die. */
        if( p_playlist->p_input )
        {
            /* This input is dead. Remove it ! */
            if( p_playlist->p_input->b_dead )
            {
                input_thread_t *p_input;

                p_input = p_playlist->p_input;
                p_playlist->p_input = NULL;

                /* Release the playlist lock, because we may get stuck
                 * in input_DestroyThread() for some time. */
                vlc_mutex_unlock( &p_playlist->object_lock );

                /* Destroy input */
                input_DestroyThread( p_input );

                /* Unlink current input
                 * (_after_ input_DestroyThread for vout garbage collector) */
                vlc_object_detach( p_input );

                /* Destroy object */
                vlc_object_destroy( p_input );

                i_vout_destroyed_date = 0;
                i_sout_destroyed_date = 0;

                /* Check for autodeletion */
                if( p_autodelete_item )
                {
                    playlist_ItemDelete( p_autodelete_item );
                    p_autodelete_item = 0;
                }

                continue;
            }
            /* This input is dying, let him do */
            else if( p_playlist->p_input->b_die )
            {
                ;
            }
            /* This input has finished, ask him to die ! */
            else if( p_playlist->p_input->b_error
                      || p_playlist->p_input->b_eof )
            {
                input_StopThread( p_playlist->p_input );

                if( p_playlist->pp_items[p_playlist->i_index]->b_autodeletion )
                {
                    /* This ain't pretty but hey it works */
                    p_autodelete_item =
                        p_playlist->pp_items[p_playlist->i_index];
                    p_playlist->pp_items[p_playlist->i_index] =
                        playlist_ItemNew( p_playlist,
                                          p_autodelete_item->input.psz_uri, 0);

                    vlc_mutex_unlock( &p_playlist->object_lock );
                    p_playlist->i_status = PLAYLIST_STOPPED;
                    playlist_Delete( p_playlist, p_playlist->i_index );
                    p_playlist->i_status = PLAYLIST_RUNNING;
                    vlc_mutex_lock( &p_playlist->object_lock );
                }

                SkipItem( p_playlist, 1 );
                vlc_mutex_unlock( &p_playlist->object_lock );
                continue;
            }
            else if( p_playlist->p_input->i_state != INIT_S )
            {
                vlc_mutex_unlock( &p_playlist->object_lock );
                i_vout_destroyed_date =
                    ObjectGarbageCollector( p_playlist, VLC_OBJECT_VOUT,
                                            i_vout_destroyed_date );
                i_sout_destroyed_date =
                    ObjectGarbageCollector( p_playlist, VLC_OBJECT_SOUT,
                                            i_sout_destroyed_date );
                vlc_mutex_lock( &p_playlist->object_lock );
            }
        }
        else if( p_playlist->i_status != PLAYLIST_STOPPED )
        {
            /* Start another input. Let's check if that item has
             * been forced. In that case, we override random (by not skipping)
             * and play-and-stop */
            vlc_bool_t b_forced;
            var_Get( p_playlist, "prevent-skip", &val );
            b_forced = val.b_bool;
            if( val.b_bool == VLC_FALSE )
            {
                SkipItem( p_playlist, 0 );
            }
            /* Reset forced status */
            val.b_bool = VLC_FALSE;
            var_Set( p_playlist, "prevent-skip", val );
            /* Check for play-and-stop */
            var_Get( p_playlist, "play-and-stop", &val );
            if( val.b_bool == VLC_FALSE || b_forced == VLC_TRUE )
            {
                PlayItem( p_playlist );
            }
        }
        else if( p_playlist->i_status == PLAYLIST_STOPPED )
        {
            vlc_mutex_unlock( &p_playlist->object_lock );
            i_sout_destroyed_date =
                ObjectGarbageCollector( p_playlist, VLC_OBJECT_SOUT, mdate() );
            i_vout_destroyed_date =
                ObjectGarbageCollector( p_playlist, VLC_OBJECT_VOUT, mdate() );
            vlc_mutex_lock( &p_playlist->object_lock );
        }
        vlc_mutex_unlock( &p_playlist->object_lock );

        msleep( INTF_IDLE_SLEEP );
    }

    /* If there is an input, kill it */
    while( 1 )
    {
        vlc_mutex_lock( &p_playlist->object_lock );

        if( p_playlist->p_input == NULL )
        {
            vlc_mutex_unlock( &p_playlist->object_lock );
            break;
        }

        if( p_playlist->p_input->b_dead )
        {
            input_thread_t *p_input;

            /* Unlink current input */
            p_input = p_playlist->p_input;
            p_playlist->p_input = NULL;
            vlc_mutex_unlock( &p_playlist->object_lock );

            /* Destroy input */
            input_DestroyThread( p_input );
            /* Unlink current input (_after_ input_DestroyThread for vout
             * garbage collector)*/
            vlc_object_detach( p_input );

            /* Destroy object */
            vlc_object_destroy( p_input );
            continue;
        }
        else if( p_playlist->p_input->b_die )
        {
            /* This input is dying, leave him alone */
            ;
        }
        else if( p_playlist->p_input->b_error || p_playlist->p_input->b_eof )
        {
            input_StopThread( p_playlist->p_input );
            vlc_mutex_unlock( &p_playlist->object_lock );
            continue;
        }
        else
        {
            p_playlist->p_input->b_eof = 1;
        }

        vlc_mutex_unlock( &p_playlist->object_lock );

        msleep( INTF_IDLE_SLEEP );
    }

    /* close all remaining sout */
    while( ( p_obj = vlc_object_find( p_playlist,
                                      VLC_OBJECT_SOUT, FIND_CHILD ) ) )
    {
        vlc_object_release( p_obj );
        sout_DeleteInstance( (sout_instance_t*)p_obj );
    }

    /* close all remaining vout */
    while( ( p_obj = vlc_object_find( p_playlist,
                                      VLC_OBJECT_VOUT, FIND_CHILD ) ) )
    {
        vlc_object_detach( p_obj );
        vlc_object_release( p_obj );
        vout_Destroy( (vout_thread_t *)p_obj );
    }
}
Exemple #8
0
/**
 * Do a playlist action.
 *
 * If there is something in the playlist then you can do playlist actions.
 * \param p_playlist the playlist to do the command on
 * \param i_command the command to do
 * \param i_arg the argument to the command. See playlist_command_t for details
 */
void playlist_Command( playlist_t * p_playlist, playlist_command_t i_command,
                       int i_arg )
{
    vlc_value_t val;

    vlc_mutex_lock( &p_playlist->object_lock );

    if( p_playlist->i_size <= 0 )
    {
        vlc_mutex_unlock( &p_playlist->object_lock );
        return;
    }

    switch( i_command )
    {
    case PLAYLIST_STOP:
        p_playlist->i_status = PLAYLIST_STOPPED;
        if( p_playlist->p_input )
        {
            input_StopThread( p_playlist->p_input );
            val.i_int = p_playlist->i_index;
            /* Does not matter if we unlock here */
            vlc_mutex_unlock( &p_playlist->object_lock );
            var_Set( p_playlist, "item-change",val );
            vlc_mutex_lock( &p_playlist->object_lock );
        }
        break;

    case PLAYLIST_PLAY:
        p_playlist->i_status = PLAYLIST_RUNNING;
        if( !p_playlist->p_input && p_playlist->i_enabled != 0 )
        {
            PlayItem( p_playlist );
        }
        if( p_playlist->p_input )
        {
            val.i_int = PLAYING_S;
            var_Set( p_playlist->p_input, "state", val );
        }
        break;

    case PLAYLIST_PAUSE:
        val.i_int = 0;
        if( p_playlist->p_input )
            var_Get( p_playlist->p_input, "state", &val );

        if( val.i_int == PAUSE_S )
        {
            p_playlist->i_status = PLAYLIST_RUNNING;
            if( p_playlist->p_input )
            {
                val.i_int = PLAYING_S;
                var_Set( p_playlist->p_input, "state", val );
            }
        }
        else
        {
            p_playlist->i_status = PLAYLIST_PAUSED;
            if( p_playlist->p_input )
            {
                val.i_int = PAUSE_S;
                var_Set( p_playlist->p_input, "state", val );
            }
        }
        break;

    case PLAYLIST_SKIP:
        p_playlist->i_status = PLAYLIST_STOPPED;
        if( p_playlist->i_enabled == 0)
        {
            break;
        }
        SkipItem( p_playlist, i_arg );
        if( p_playlist->p_input )
        {
            input_StopThread( p_playlist->p_input );
        }
        p_playlist->i_status = PLAYLIST_RUNNING;
        break;

    case PLAYLIST_GOTO:
        if( i_arg >= 0 && i_arg < p_playlist->i_size &&
            p_playlist->i_enabled != 0 )
        {
            p_playlist->i_index = i_arg;
            if( p_playlist->p_input )
            {
                input_StopThread( p_playlist->p_input );
            }
            val.b_bool = VLC_TRUE;
            var_Set( p_playlist, "prevent-skip", val );
            p_playlist->i_status = PLAYLIST_RUNNING;
        }
        break;

    default:
        msg_Err( p_playlist, "unknown playlist command" );
        break;
    }

    vlc_mutex_unlock( &p_playlist->object_lock );
#if 0
    val.b_bool = VLC_TRUE;
    var_Set( p_playlist, "intf-change", val );
#endif
    return;
}
Exemple #9
0
// Thread which performs an insert to playlist
void insert_looper(void *data) {
	std::set<PlaylistInterface *>::const_iterator i;
	std::set<playlist_interface *>::const_iterator j;

	PlInsertItems * items = (PlInsertItems *)data;
	Playlist *playlist = items->playlist;

	// Stop the list being changed while we add these items
	playlist->Lock();

	// First vetting of the list, and recurse through directories
	std::vector<std::string> vetted_items;
	std::vector<std::string>::const_iterator k = items->items.begin();
	while(k != items->items.end() && playlist->active) {
		additems(&(vetted_items), *k++, MAXRECURSEDEPTH);
	}
	std::vector<PlayItem> newitems;
	if(vetted_items.size() > 0) {
		char cwd[PATH_MAX + 1];
		std::vector<std::string>::const_iterator path;

		if (!getcwd(cwd, PATH_MAX)) {
			alsaplayer_error("Failed to get current working directory");
			cwd[0] = 0;
		}
		// Check items for adding to list
		for(path = vetted_items.begin(); path != vetted_items.end() && playlist->active; path++) {
			// Check that item is valid
			if(!playlist->CanPlay(*path)) {
				//alsaplayer_error("Can't find a player for `%s'\n", path->c_str());
			} else {
				newitems.push_back(PlayItem(*path));
			}
		}
	}
	// Check position is valid
	if(playlist->queue.size() < items->position) {
		items->position = playlist->queue.size();
	}
	// Add to list
	playlist->queue.insert(playlist->queue.begin() + items->position,
						   newitems.begin(),
						   newitems.end());
	if(playlist->curritem > items->position)
		playlist->curritem += newitems.size();

	if(playlist->curritem == 0) {
		playlist->curritem = 1;
	}

	// Tell the subscribing interfaces about the changes
	playlist->LockInterfaces();
	if(playlist->interfaces.size() > 0) {
		for(i = playlist->interfaces.begin();
			i != playlist->interfaces.end(); i++) {
			(*i)->CbInsert(newitems, items->position);
			(*i)->CbSetCurrent(playlist->curritem);
		}
	}
	if (playlist->cinterfaces.size() > 0) {
		for (j = playlist->cinterfaces.begin();
			j != playlist->cinterfaces.end(); j++) {
			(*j)->cbinsert((*j)->data, newitems, items->position);
			(*j)->cbsetcurrent((*j)->data, playlist->curritem);
		}
	}
	playlist->UnlockInterfaces();
	// Free the list again

	/* Metadate gathering is disabled for now. It completely
	 * breaks streaming and it was never very efficient. A complete
	 * reimplementation will follow shortly */
	if (playlist->active)
		info_looper(playlist);

	playlist->Unlock();
	delete items;
}