4

I am having problems with launching Nokia's own video player from my application that I just don't seem to be able to solve.

My first attempt included calling

Qt.openUrlExternally(url)

from QML and that seemed to do the trick just fine, except that it opened the browser every time and used it instead of the video-suite (native player).

Next I tried cuteTube -approach where I start new process like this:

QStringList args;
args << url;
QProcess *player = new QProcess();
connect(player, SIGNAL(finished(int, QProcess::ExitStatus)), player, SLOT(deleteLater()));
player->start("/usr/bin/video-suite", args);

That worked, except that it required video-suite to be closed upon calling player->start, otherwise it did nothing.

My third attempt involved starting the video-suite via QDBus, but that didn't work any better:

QList<QVariant> args;
QStringList urls;
urls << url;
args.append(urls);

QDBusMessage message = QDBusMessage::createMethodCall(
    "com.nokia.VideoSuite",
    "/",
    "com.nokia.maemo.meegotouch.VideoSuiteInterface",
    "play");

message.setArguments(args);
message.setAutoStartService(true);

QDBusConnection bus = QDBusConnection::sessionBus();

if (bus.isConnected()) {
    bus.send(message);
} else {
    qDebug() << "Error, QDBus is not connected";
}

The problem with this is that it requires video-suite to be up and running - autoStartService parameter didn't help either. If video-suite isn't running already, the call opens it just fine but, alas, no video starts to play.

Eventually I tried using also VideoSuiteInterface, but even having the program compile with it seemed to be difficult. When I eventually managed to compile and link all relevant libraries, the results didn't differ from option 3 above.

So, is there a way to use either VideoSuiteInterface directly or via DBus so that it would start video playback regardless of the current state of the application?

4

1 回答 1

1

The solution was actually simpler than I really thought initially; the VideoSuiteInterface -approach worked after all. All it took was to use it properly. Here are the full sources should anyone want to try it themselves.

player.h:

#ifndef PLAYER_H
#define PLAYER_H
#include <QObject>
#include <maemo-meegotouch-interfaces/videosuiteinterface.h>

class Player : public QObject {
  Q_OBJECT
private:
  VideoSuiteInterface* videosuite;
public:
  Player(QObject *parent = 0);
  Q_INVOKABLE void play(QString url);
};
#endif // PLAYER_H

player.cpp:

#include "player.h"
#include <QObject>
#include <QStringList>
#include <QtDeclarative>

Player::Player(QObject *parent) : QObject(parent) {}

void Player::play(QString url) {
  QList<QVariant> args;
  QStringList urls;
  urls << url;
  args.append(urls);

  videosuite = new VideoSuiteInterface();
  videosuite->play(urls);
}

In addition you may want to connect some signals to make the UI more responsive, but basically that should do the trick.

Finally, you need to remember to add following to your .pro file and you are good to go:

CONFIG += videosuiteinterface-maemo-meegotouch
于 2012-04-10T20:09:22.773 回答