有没有办法从任意点启动Phonon媒体对象中的流?

时间:2012-05-01 16:20:42

标签: c++ qt phonon

我正在编写一个应用程序,在Mac OS X上的Qt 4.8.1中收听播客。现在,我正在设置我的MediaObject以使用播客RSS项目中的机箱URL,如下所示:

mediaObj->setCurrentSource(Phonon::MediaSource(QUrl(idx.data(Metadata::Enclosure).toString())));

注意:idxQModelIndex,与用户在QStandardItem窗口小部件中点击的模型中的QTreeView相对应。

但我现在有两个问题。

  1. 每当我暂停流并再次启动它时,它就从头开始。没那么有帮助。 : - (
  2. 如果我使用我的Phonon::SeekSlider小部件跳到我还没有缓冲的流的一部分,我会被反弹到流的开头。
  3. 我(可能存在缺陷)的想法是,如果我能想出让mediaObj从流中的特定时间开始播放的方法,我可以解决这两个问题。所以,我试过这个:

    void BrodCastMainWin::pauseStream()
    {
        //save the "left off at" point in the stream
        qDebug() << "current time is:" << currentTime;
        qDebug() << "Saving place at" << currentTimeString
                 << "in item" << nowPlaying.data(Qt::DisplayRole).toString();
        //need to use QModelIndex for setData()
        QModelIndex nowPlayingHandle = nowPlaying;
        feed.setData(nowPlayingHandle, QVariant(currentTime), Metadata::LeftOffAt);
        //pause the stream
        mediaObj->pause();
    }
    
    void BrodCastMainWin::playStream()
    {
        //seek to the "left off at" point in the stream
        qDebug() << "Trying to seek to" << convertTime(nowPlaying.data(Metadata::LeftOffAt).toLongLong())
                 << "in item" << nowPlaying.data(Qt::DisplayRole).toString();
        mediaObj->seek(nowPlaying.data(Metadata::LeftOffAt).toLongLong());
        //play the file
        mediaObj->play();
    }
    

    注意:currentTime是从发出的最后一个tick()信号mediaObj开始的时间。我尝试使用currentTime()中的mediaObj方法获取此数据,但它无效。但这是另一天的战斗。同样,currentTimeString是人类可读格式的相同信息。

    唉,它不起作用:-(。这是我播放流时代码所发生的事情:

    current time is: 32153 
    Saving place at "00:32" in item "Leo Laporte - The Tech Guy 867" 
    switching button to 'play'
    

    Groovy的。但是当我再次尝试时:

    Trying to seek to "00:32" in item "Leo Laporte - The Tech Guy 867" 
    Playing/Loading/Buffering; switching button to 'pause' 
    current time is: 0 
    Saving place at "00:00" in item "Leo Laporte - The Tech Guy 867" 
    switching button to 'play' 
    Trying to seek to "00:00" in item "Leo Laporte - The Tech Guy 867" 
    Playing/Loading/Buffering; switching button to 'pause' 
    

    我完全糊涂了。好像我试图让Phonon以一种它不想要的方式行事。 我担心,这似乎是Phonon模块长期存在的问题,我可能不得不以其他方式实现流。帮助?

1 个答案:

答案 0 :(得分:1)

好吧,看来我太开心了。我正在使用一个按钮进行播放/暂停。我只需要改变这个:

void BrodCastMainWin::handleMediaState(Phonon::State state, Phonon::State)
{
    switch (state)
    {
    case Phonon::PlayingState:
    case Phonon::LoadingState:
    case Phonon::BufferingState:
        qDebug() << "Playing/Loading/Buffering; switching button to 'pause'";
        //If we're playing, the button should pause
        ui->playPauseButton->setIcon(QIcon(":/assets/stock_media-pause.svg"));
        connect(ui->playPauseButton, SIGNAL(clicked()),
                this, SLOT(pauseStream()));
        break;
    case Phonon::PausedState:
    case Phonon::StoppedState:
        qDebug() << "switching button to 'play'";
        //if we're paused, the button should play
        ui->playPauseButton->setIcon(QIcon(":/assets/stock_media-play.svg"));
        connect(ui->playPauseButton, SIGNAL(clicked()),
                this, SLOT(playStream()));
    case Phonon::ErrorState:
        //additionally, if there's an error, do error handling.
        break;
    default:
        break;
    }
}

......对此:

void BrodCastMainWin::handleMediaState(Phonon::State state, Phonon::State)
{
    switch (state)
    {
    case Phonon::PlayingState:
        qDebug() << "Playing/Loading/Buffering; switching button to 'pause'";
        //If we're playing, the button should pause
        ui->playPauseButton->setIcon(QIcon(":/assets/stock_media-pause.svg"));
        connect(ui->playPauseButton, SIGNAL(clicked()),
                this, SLOT(pauseStream()));
        break;
    case Phonon::PausedState:
        qDebug() << "switching button to 'play'";
        //if we're paused, the button should play
        ui->playPauseButton->setIcon(QIcon(":/assets/stock_media-play.svg"));
        connect(ui->playPauseButton, SIGNAL(clicked()),
                this, SLOT(playStream()));
        break;
    case Phonon::ErrorState:
        //additionally, if there's an error, do error handling.
        break;
    case Phonon::LoadingState:
    case Phonon::BufferingState:
    case Phonon::StoppedState:
    default:
        break;
    }
}

当然,我最终也想要处理其他州。但这解决了我的第一个问题。另一个问题可能要等到另一天。