有没有办法从任意点开始在 Phonon 媒体对象中启动流
Is there any way to start a stream in a Phonon Media Object from an arbitrary point?
我正在编写一个应用程序,用于在Mac OS X上收听Qt 4.8.1中的播客。现在,我正在将MediaObject
设置为使用播客 RSS 项目中的附件 URL,如下所示:
mediaObj->setCurrentSource(Phonon::MediaSource(QUrl(idx.data(Metadata::Enclosure).toString())));
注意:idx
是一个QModelIndex
,对应于用户在QTreeView
小部件中单击的模型中的QStandardItem
。
不过,我现在有两个问题。
- 每当我暂停流并重新启动它时,它都会从头开始。没那么有帮助。:-(
- 如果我使用
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
是截至mediaObj
发出最后一个tick()
信号的时间。我试图在mediaObj
中使用currentTime()
方法获取这些数据,但没有奏效。但这是另一天的战斗。同样,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 模块长期存在的问题,我可能不得不以其他方式实现流。帮助?
好吧,看来我太花哨了。我使用一个按钮进行播放/暂停。我只需要改变这个:
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;
}
}
当然,我最终也会想处理其他状态。但这解决了我的第一个问题。另一个问题可能要等到另一天。
相关文章:
- 什么时候调用组成单元对象的析构函数
- 对RValue对象调用的LValue ref限定成员函数
- CMake-按正确顺序将项目与C运行时对象文件链接
- 空基优化子对象的地址
- 将对象数组的引用传递给函数
- 你能重载对象变量名本身返回的内容吗
- C++使用整数的压缩数组初始化对象
- 找不到成员对象:没有名为get_event()的成员,也处理多态性和向量
- 将对象移动到std::shared_ptr
- 代理对象的常量正确性
- 提升 ASIO 无法识别计时器对象
- 将Ref对象作为类成员
- 将包含C样式数组的对象初始化为成员变量(C++)
- 如何返回一个类的两个对象相加的结果
- 使用std::函数映射对象方法
- 是否需要删除包含对象的"pair"?
- 处理媒体循环循环循环通过向量中的对象的各个方面
- 暂停视频后C++如何访问构建器 6 媒体播放器对象中的当前帧
- 有没有办法从任意点开始在 Phonon 媒体对象中启动流
- 无效/未定义的QML相机的媒体对象属性