0

我正在编写一个应用程序来收听 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小部件向前跳到我尚未缓冲的流的一部分,我将被弹回到流的开头。

我(可能有缺陷)的想法是,如果我能找到一种方法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'

时髦的。但是当我再次尝试播放时:

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 模块的一个长期存在的问题,我可能不得不以其他方式实现流。帮助?

4

1 回答 1

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;
    }
}

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

于 2012-05-02T00:21:03.357 回答