Ejemplo n.º 1
0
void MainWidget::currentChanged_slot(PlaylistMember *newCurrent)
{
    if(m_removeCurrent)
    {
        QFile file(m_playlistWidget->getPrevious()->url.split('/').at(m_playlistWidget->getPrevious()->url.split('/').size()-1));
        file.remove();
        m_removeCurrent = false;
    }
    m_cacheCurrent->setChecked(newCurrent->cached);

    if(newCurrent->cached)
        m_player->setMedia(QUrl::fromLocalFile(newCurrent->localfile));
    else
        m_player->setPlaylist(m_mediaWebPlaylist);

    m_currentLabel->setText(newCurrent->artist+" - "+newCurrent->title);
    m_mediaWebPlaylist->setCurrentIndex(m_playlistWidget->getCurrentId());
    m_seekslider->setMaximum(newCurrent->duration*1000);
    m_seekslider->setValue(0);

    if(m_playState)
    {
        emit playStateChanged(true);
        m_player->play();
    }
    else
        emit playStateChanged(false);
}
void FullscreenVideoControllerGtk::createHud()
{
    m_hudWindow = gtk_window_new(GTK_WINDOW_POPUP);
    gtk_window_set_gravity(GTK_WINDOW(m_hudWindow), GDK_GRAVITY_SOUTH_WEST);
    gtk_window_set_type_hint(GTK_WINDOW(m_hudWindow), GDK_WINDOW_TYPE_HINT_NORMAL);

    m_hudMotionNotifySignalId = g_signal_connect(m_hudWindow, "motion-notify-event", G_CALLBACK(onFullscreenGtkMotionNotifyEvent), this);

#ifdef GTK_API_VERSION_2
    GtkWidget* hbox = gtk_hbox_new(FALSE, 4);
#else
    GtkWidget* hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 4);
#endif
    gtk_container_add(GTK_CONTAINER(m_hudWindow), hbox);

    m_playPauseAction = gtk_action_new("play", _("Play / Pause"), _("Play or pause the media"), PAUSE_ICON_NAME);
    m_playActionActivateSignalId = g_signal_connect(m_playPauseAction, "activate", G_CALLBACK(togglePlayPauseActivated), this);

    GtkWidget* item = gtk_action_create_tool_item(m_playPauseAction);
    gtk_box_pack_start(GTK_BOX(hbox), item, FALSE, TRUE, 0);

    GtkWidget* label = gtk_label_new(_("Time:"));
    gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, TRUE, 0);

    GtkAdjustment* adjustment = GTK_ADJUSTMENT(gtk_adjustment_new(0.0, 0.0, 100.0, 0.1, 1.0, 1.0));
#ifdef GTK_API_VERSION_2
    m_timeHScale = gtk_hscale_new(adjustment);
#else
    m_timeHScale = gtk_scale_new(GTK_ORIENTATION_HORIZONTAL, adjustment);
#endif
    gtk_scale_set_draw_value(GTK_SCALE(m_timeHScale), FALSE);
    gtk_range_set_show_fill_level(GTK_RANGE(m_timeHScale), TRUE);
    m_timeScaleButtonPressedSignalId = g_signal_connect(m_timeHScale, "button-press-event", G_CALLBACK(timeScaleButtonPressed), this);
    m_timeScaleButtonReleasedSignalId = g_signal_connect(m_timeHScale, "button-release-event", G_CALLBACK(timeScaleButtonReleased), this);
    m_hscaleUpdateId = g_signal_connect(m_timeHScale, "value-changed", G_CALLBACK(timeScaleValueChanged), this);

    gtk_box_pack_start(GTK_BOX(hbox), m_timeHScale, TRUE, TRUE, 0);

    m_timeLabel = gtk_label_new("");
    gtk_box_pack_start(GTK_BOX(hbox), m_timeLabel, FALSE, TRUE, 0);

    // Volume button.
    m_volumeButton = gtk_volume_button_new();
    gtk_box_pack_start(GTK_BOX(hbox), m_volumeButton, FALSE, TRUE, 0);
    gtk_scale_button_set_value(GTK_SCALE_BUTTON(m_volumeButton), m_player->volume());
    m_volumeUpdateId = g_signal_connect(m_volumeButton, "value-changed", G_CALLBACK(volumeValueChanged), this);

    m_exitFullscreenAction = gtk_action_new("exit", _("Exit Fullscreen"), _("Exit from fullscreen mode"), EXIT_FULLSCREEN_ICON_NAME);
    m_exitFullcreenActionActivateSignalId = g_signal_connect(m_exitFullscreenAction, "activate", G_CALLBACK(exitFullscreenActivated), this);
    g_object_set(m_exitFullscreenAction, "icon-name", EXIT_FULLSCREEN_ICON_NAME, NULL);
    item = gtk_action_create_tool_item(m_exitFullscreenAction);
    gtk_box_pack_start(GTK_BOX(hbox), item, FALSE, TRUE, 0);

    m_progressBarUpdateId = g_timeout_add(PROGRESS_BAR_UPDATE_INTERVAL, reinterpret_cast<GSourceFunc>(progressBarUpdateCallback), this);

    playStateChanged();
}
Ejemplo n.º 3
0
void MainWidget::playOrPause()
{
    if(m_playState)
        m_player->pause();
    else
        m_player->play();

    emit playStateChanged(!m_playState);
}
Ejemplo n.º 4
0
void PlaybackManager::play()
{
    int projectLength = editor()->layers()->projectLength();

    mStartFrame = ( mIsRangedPlayback ) ? mMarkInFrame : 1;
    mEndFrame = ( mIsRangedPlayback ) ? mMarkOutFrame : projectLength;

    if ( editor()->currentFrame() >= mEndFrame )
    {
        editor()->scrubTo( mStartFrame );
    }

    mTimer->setInterval( 1000.0f / mFps );
    mTimer->start();
    emit playStateChanged(true);
}
Ejemplo n.º 5
0
MainWidget::MainWidget(const QString &token, const QString &user_id, QWidget *parent)
    : QWidget(parent), m_token(token), m_user_id(user_id), m_playState(false)
{
    m_removeCurrent = false;
    m_player = new QMediaPlayer;
    m_player->setVolume(100);

    m_mediaWebPlaylist = new QMediaPlaylist(m_player);
    m_mediaWebPlaylist->setObjectName("web");
    m_player->setPlaylist(m_mediaWebPlaylist);

    loadUserPlaylist();
    this->resize(800, 600);
    this->setWindowTitle("VK Music Player");


    QDir dir("./cache/");
    if(!dir.exists())
        dir.mkpath(".");

    QGridLayout* mainLayout = new QGridLayout;

    m_currentLabel = new QLabel;
    m_currentLabel->setFont(QFont("Arial", 16));
    m_currentLabel->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored);
    mainLayout->addWidget(m_currentLabel, 0, 0, 1, 9, Qt::AlignCenter);

    ImageButton *prevButton = new ImageButton("prevbutton.png");
    mainLayout->addWidget(prevButton, 2, 3, 1, 1, Qt::AlignTop | Qt::AlignRight);

    m_playPauseButton = new ImageButton("playbutton.png");
    mainLayout->addWidget(m_playPauseButton, 2, 4, 1, 1, Qt::AlignTop);

    ImageButton *nextButton = new ImageButton("nextbutton.png");
    mainLayout->addWidget(nextButton, 2, 5, 1, 1, Qt::AlignTop | Qt::AlignLeft);

    m_playlistWidget = new PlaylistWidget;
    mainLayout->addWidget(m_playlistWidget, 3, 0, 3, 9);

    m_seekslider = new QSlider;
    m_seekslider->setOrientation(Qt::Horizontal);
    mainLayout->addWidget(m_seekslider, 1, 0, 1, 7);

    m_volumeSlider = new QSlider;
    m_volumeSlider->setOrientation(Qt::Horizontal);
    m_volumeSlider->setMaximum(100);
    m_volumeSlider->setValue(100);
    m_volumeSlider->setSingleStep(1);
    mainLayout->addWidget(m_volumeSlider, 1, 7, 1, 2);

    m_timeLabel = new QLabel;
    m_timeLabel->setText("0:00");
    mainLayout->addWidget(m_timeLabel, 2, 0, 1, 2, Qt::AlignTop);

    m_volumeLabel = new QLabel;
    m_volumeLabel->setText(QString::number(m_player->volume())+"%");
    mainLayout->addWidget(m_volumeLabel, 2, 7, 1, 2, Qt::AlignTop | Qt::AlignHCenter);

    m_cacheCurrent = new QCheckBox(tr("&Save"));
    mainLayout->addWidget(m_cacheCurrent, 2, 7, 1, 2, Qt::AlignBottom | Qt::AlignRight);

    m_searchEdit = new QLineEdit;
    m_searchEdit->setPlaceholderText(tr("Search"));
    mainLayout->addWidget(m_searchEdit, 2, 0, 1, 8, Qt::AlignBottom);

    this->setLayout(mainLayout);

    connect(this, SIGNAL(playlistReady()),
            SLOT(fillPlaylistWidget_slot()));
    connect(this, SIGNAL(playStateChanged(bool)),
            SLOT(playStateChanged_slot(bool)));

    connect(m_playPauseButton, SIGNAL(pressed()), this, SLOT(playOrPause()));

    connect(nextButton, &ImageButton::pressed,
            [=](){
                m_playlistWidget->setCurrent(m_playlistWidget->getCurrentId()+1);
                m_player->play();
                emit playStateChanged(true);
            });

    connect(prevButton, &ImageButton::pressed,
            [=](){
                m_playlistWidget->setCurrent(m_playlistWidget->getCurrentId()-1);
                m_player->play();
                emit playStateChanged(true);
            });


    connect(m_player, SIGNAL(mediaStatusChanged(QMediaPlayer::MediaStatus)),
            this, SLOT(mediaStatusChanged_slot(QMediaPlayer::MediaStatus)));

    connect(m_playlistWidget, SIGNAL(currentChanged(PlaylistMember*)),
            this, SLOT(currentChanged_slot(PlaylistMember*)));

    connect(m_player, SIGNAL(positionChanged(qint64)),
            this, SLOT(updateSlider(qint64)));

    connect(m_player, &QMediaPlayer::volumeChanged,
            [=](int v){ m_volumeLabel->setText(QString::number(v)+"%"); });

    connect(m_seekslider, &QSlider::sliderReleased,
            [=](){ m_player->setPosition(m_seekslider->value()); } );
    connect(m_seekslider, &QSlider::sliderMoved,
            [=](int time){
                m_timeLabel->setText(QString("%1:%2").arg((int)time/1000/60).arg(time/1000-time/1000/60*60 < 10 ?
                                                                                     QString("0")+QString::number(time/1000-time/1000/60*60) : QString::number(time/1000-time/1000/60*60)));
            });

    connect(m_volumeSlider,
            &QSlider::valueChanged,
            [=](int v){ m_player->setVolume(v); });

    connect(m_cacheCurrent, SIGNAL(toggled(bool)),
            this, SLOT(cacheCurrentCheckboxChecked(bool)));

    connect(m_searchEdit, SIGNAL(textChanged(QString)),
            m_playlistWidget, SLOT(searchMembersByName(QString)));
}
Ejemplo n.º 6
0
FullScreenPlayer::FullScreenPlayer(const QUrl &url)
    : QWidget(0)
    , m_seekSlider(new Phonon::SeekSlider(this))
    , m_volumeSlider(new Phonon::VolumeSlider(this))
{
    m_mediaObject = new Phonon::MediaObject();
    m_mediaObject->setTickInterval(1000);

    m_videoWidget = new Phonon::VideoWidget(this);
    Phonon::createPath(m_mediaObject, m_videoWidget);

    m_audioOutput = new Phonon::AudioOutput(Phonon::VideoCategory);
    connect(m_audioOutput, SIGNAL(mutedChanged(bool)), this, SLOT(muteStateChanged(bool)));

    Phonon::createPath(m_mediaObject, m_audioOutput);

    m_seekSlider->setMediaObject(m_mediaObject);
    m_seekSlider->setIconVisible(false);

    m_volumeSlider->setAudioOutput(m_audioOutput);
    m_volumeSlider->setMuteVisible(false);
    m_volumeSlider->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Maximum);

    m_playbackTime = new QLabel(QString("00:00:00"), this);

    m_play = new QToolButton(this);
    m_play->setIcon(koIcon("media-playback-start"));
    m_play->setToolTip(i18n("Play"));
    connect(m_play, SIGNAL(clicked()), this, SLOT(play()));

    m_pause = new QToolButton(this);
    m_pause->setIcon(koIcon("media-playback-pause"));
    m_pause->setToolTip(i18n("Pause"));
    connect(m_pause, SIGNAL(clicked()), this, SLOT(pause()));

    m_stop = new QToolButton(this);
    m_stop->setIcon(koIcon("media-playback-stop"));
    m_stop->setToolTip(i18n("Stop"));
    connect(m_stop, SIGNAL(clicked()), this, SLOT(stop()));

    m_volumeIconMuted = new QToolButton(this);
    m_volumeIconMuted->setIcon(koIcon("audio-volume-muted"));
    m_volumeIconMuted->setToolTip(i18n("Unmute"));
    connect(m_volumeIconMuted, SIGNAL(clicked()), this, SLOT(unmute()));

    m_volumeIconUnmuted = new QToolButton(this);
    m_volumeIconUnmuted->setIcon(koIcon("audio-volume-medium"));
    m_volumeIconUnmuted->setToolTip(i18n("Mute"));
    connect(m_volumeIconUnmuted, SIGNAL(clicked()), this, SLOT(mute()));

    QHBoxLayout *playbackControls = new QHBoxLayout();
    playbackControls->addWidget(m_play);
    playbackControls->addWidget(m_pause);
    playbackControls->addWidget(m_stop);
    playbackControls->addWidget(m_seekSlider);
    playbackControls->addWidget(m_playbackTime);
    playbackControls->addWidget(m_volumeIconMuted);
    playbackControls->addWidget(m_volumeIconUnmuted);
    playbackControls->addWidget(m_volumeSlider);
    playbackControls->setSizeConstraint(QLayout::SetFixedSize);

    QVBoxLayout *layout = new QVBoxLayout;
    layout->addWidget(m_videoWidget);
    layout->addLayout(playbackControls);
    layout->setMargin(0);
    setLayout(layout);
    show();
    setWindowState(Qt::WindowFullScreen);

    m_mediaObject->setCurrentSource(url);
    connect(m_mediaObject, SIGNAL(finished()), this, SLOT(stop()));
    connect(m_mediaObject, SIGNAL(stateChanged(Phonon::State,Phonon::State)),
            this, SLOT(playStateChanged(Phonon::State,Phonon::State)));
    connect(m_mediaObject, SIGNAL(tick(qint64)), this, SLOT(updatePlaybackTime(qint64)));

    play();

    mute();
    unmute();
}
Ejemplo n.º 7
0
void PlaybackManager::stop()
{
    mTimer->stop();
    stopSounds();
    emit playStateChanged(false);
}
Ejemplo n.º 8
0
VideoPlayer::VideoPlayer(QString programPath, QWidget *parent) :
    QWidget(parent)
  ,programDir(programPath)
  ,WIDTH(600)
  ,HEIGHT(380)
  ,videoNameWidth(300)
  ,videoListWidth(200)
  ,hideButtonsTime(2000)
  ,forwardStep(5)
  ,retreatStep(5)
  ,volumnChangeStep(5)
  ,hideCursor(false)
  ,keepAwakeTimes(0)
{
    //设置窗口无边框
    this->setWindowFlags(Qt::FramelessWindowHint | Qt::WindowMinimizeButtonHint);
    this->installEventFilter(this);

    //初始化窗口位置、大小
    QDesktopWidget desktop;
    setGeometry((desktop.width()-WIDTH)/2, (desktop.height()-HEIGHT)/2, WIDTH, HEIGHT);
    setObjectName("videoPlayer");

    //背景label
    lab_background = new QLabel(this);
    lab_background->setGeometry(0, 0, WIDTH, HEIGHT);
    lab_background->setObjectName("lab_background");

//    videoList = new VideoList(0, 25, videoListWidth, this->height()-50, false, this);
//    videoList->show();

    //设置鼠标跟踪,响应鼠标移动事件
    this->setMouseTracking(true);
    lab_background->setMouseTracking(true);

    //
    videoWidget = new VideoWidget;
    videoWidget->hide();
    videoWidget->installEventFilter(this);
    videoWidget->setMouseTracking(true);

    //保持视频屏幕常亮
    helpKeepAwake = new HelpKeepAwake;

    //布局
    layout_top = new QGridLayout;
    layout_top->addWidget(lab_background, 0, 0, 1, 1);
    layout_top->addWidget(videoWidget, 0, 0, 1, 1);
    layout_top->setSpacing(0);
    layout_top->setMargin(0);
    this->setLayout(layout_top);

    //
    videoContral = new VideoContral(this);
    videoContral->setGeometry(this->x(), this->y(), this->width(), this->height());

    tbn_openVideoFile = new QToolButton(this);
    tbn_openVideoFile->setText("放入视频");
    tbn_openVideoFile->setGeometry((this->width()-126-32)/2+35, (this->height()-41)/2+95, 80, 30);
    tbn_openVideoFile->setObjectName("tbn_openVideoFile");

    //初始化多媒体播放器
    player = new QMediaPlayer(this);
    QMediaPlaylist *playlist = new QMediaPlaylist;
    QMediaPlaylist *playlistHistory = new QMediaPlaylist;

    playlist_list.append(playlistHistory);
    playlist_list.append(playlist);

    player->setVideoOutput(videoWidget);
    player->setPlaylist(playlist);
    player->setVolume(60);

    connect(tbn_openVideoFile,SIGNAL(clicked()), this, SLOT(openVideoFile()));
    connect(player, SIGNAL(metaDataChanged()), this, SLOT(metaDataChanged()));
/*    connect(this, SIGNAL(moveWindow(QPoint)), videoList, SLOT(toMoveWindow(QPoint)));*/

    //设置样式表
    setStyleSheet(
                "#videoPlayer{"
//                    "border-radius: 3px;"
                "}"
                "#lab_background{"
//                    "border-radius: 3px;"
                    "border-image: url(:/Images/videoPlayerBg.png);"
                "}"
                "#tbn_openVideoFile{"
                    "background: rgba(0, 0, 0, 30);"
                    "color: rgba(200, 255, 255, 255);"
                "}"
                );

    //创建定时器(1.5秒无鼠标动作按钮自动隐藏)
    timerHideWidgets = new QTimer(this);
    timerHideWidgets->start(hideButtonsTime);
    connect(timerHideWidgets, SIGNAL(timeout()), this, SLOT(hideWidgets_timeout()));


    //操作控制
    connect(videoWidget, SIGNAL(clicked()), this, SLOT(videoPlayPause()));
    connect(videoWidget, SIGNAL(switchFullScreen()), this, SLOT(switchFullScreen()));
//    connect(videoWidget, SIGNAL(goForward()), this, SLOT(videoGoForward()));
//    connect(videoWidget, SIGNAL(retreat()), this, SLOT(videoRetreat()));
    connect(videoWidget, SIGNAL(playJump(int)), this, SLOT(videoPlayJump(int)));
    connect(videoWidget, SIGNAL(volumnAdd()), this, SLOT(volumnAdd()));
    connect(videoWidget, SIGNAL(volumnReduce()), this, SLOT(volumnReduce()));

    connect(videoContral, SIGNAL(isHideWidget(bool)), this, SLOT(isHideWidget(bool)));
    connect(videoContral, SIGNAL(playerStop()), player, SLOT(stop()));
    connect(videoContral, SIGNAL(playPause()), this, SLOT(videoPlayPause()));
    connect(videoContral, SIGNAL(playNext()), player->playlist(), SLOT(next()));
    connect(videoContral, SIGNAL(currentMediaEnd()), this, SLOT(currentMediaEnd()));
//    connect(videoContral, SIGNAL(goForward()), this, SLOT(videoGoForward()));
//    connect(videoContral, SIGNAL(retreat()), this, SLOT(videoRetreat()));
    connect(videoContral, SIGNAL(playJump(int)), this, SLOT(videoPlayJump(int)));
    connect(videoContral, SIGNAL(switchFullScreen()), this, SLOT(switchFullScreen()));

    connect(player, SIGNAL(durationChanged(qint64)), videoContral, SLOT(durationChanged(qint64)));
    connect(player, SIGNAL(durationChanged(qint64)), this, SLOT(setVideoTitle()));
    connect(player, SIGNAL(positionChanged(qint64)), videoContral, SLOT(positionChanged(qint64)));
    connect(player, SIGNAL(stateChanged(QMediaPlayer::State)), this, SLOT(playStateChanged(QMediaPlayer::State)));

    //
    connect(videoContral, SIGNAL(itemDoubleClicked(int, int)), this, SLOT(itemDoubleClicked(int, int)));

//    videoWidget->setFocus();
    timerKeepAwake = new QTimer(this);
    connect(timerKeepAwake, SIGNAL(timeout()), this, SLOT(timeoutKeepAwake()));
}