10-30-2012 03:14 AM
Hi!
I am unable to play a video using QML. The following is my code
ForeignWindowControl {
id: videoSurface
preferredWidth: 700
preferredHeight: 700
windowId: "VideoSurface"
visible: true
updatedProperties: WindowProperty.Visible | WindowProperty.SourceSize | WindowProperty.Size
horizontalAlignment: HorizontalAlignment.Center
verticalAlignment: VerticalAlignment.Fill
}
MediaPlayer {
id: player
sourceUrl: {
app.getAbsolutePath(maxContainer.localVideoPath);/ /It gives the absolute path of the video file and it is written in CPP
}
// sourceUrl: "/app/native/assets/BB10DevAlpha.wmv"
videoOutput: VideoOutput.PrimaryDisplay
windowId: videoSurface.windowId
onMediaStateChanged: {
if (mediaState == MediaState.Started) {
console.log("player Started");
if (player.windowId == "") {
console.log("...setting the player's windowID = " + videoSurface.windowId);
player.windowId = videoSurface.windowId;
}
} else if (mediaState == MediaState.Paused) {
console.log("player Paused");
} else if (mediaState == MediaState.Stopped) {
console.log("player Stopped");
}
}
}and I am calling the play() method from a button's slot. Even I am not getting the foreign window also.
Please help me!!!
-Raju
Solved! Go to Solution.
10-31-2012 02:15 AM
its easy to use the Invocation Framework for this:
in QML only:
yourapp.invokeBoundMediaPlayer(yourPath);
and inside your app in cpp:
void YourApp::invokeBoundMediaPlayer(QString uri) {
InvokeRequest cardRequest;
cardRequest.setUri(uri);
cardRequest.setTarget("sys.mediaplayer.previewer") ;
m_invokeManager->invoke(cardRequest);
}
where m_invokeManager is initialized as
m_invokeManager(new InvokeManager(this)
you'll find the code in my OpenSource project OpenDataSpace
using Cards the MediaPlayer is "included" in your app as it would be your own Page. For me that's much better then doing this by myself with ForeignWindow
10-31-2012 02:43 AM
to be honest, i find the MediaPlayer quite buggy/unstable...might be worth going with ekke's suggestion of using the Invocation framework...
but if you insist, can you show us some logs or errors you are seeing?
10-31-2012 05:54 PM
Hello Raju,
From your code snippets, it seems like you took my Beta 2 version of the sample project on Github (the "VideoPlayerSample" as a starting point. There has been significant changes in the API from Beta 2 to Beta 3 for the "MediaPlayer" and "ForeignWindow" classes. I replaced/corrected some of your code in those parts to reflect the most recent API - after that, worked fine for me. For example:
ForeignWindowControl {
.....
updatedProperties: WindowProperty.Size |
WindowProperty.Position | WindowProperty.Visible
.....
}
And, the event handling of the media player:
MediaPlayer {
.......
onMediaStateChanged: {
if (player.mediaState == MediaState.Started) {
console.log("player Started");
......
For convenience, I am pasting my entire QML file here.
import bb.cascades 1.0
import bb.multimedia 1.0
Page {
Container {
Button {
id: playButton
text: "Play"
horizontalAlignment: HorizontalAlignment.Center
onClicked: {
if (!player.isPlaying) {
console.log("myPlayer.isPlaying = true");
player.play();
} else {
console.log("myPlayer.isPlaying = false");
player.pause();
}
}
}
ForeignWindowControl {
id: videoSurface
windowId: "myVideoSurface"
updatedProperties: WindowProperty.Size |
WindowProperty.Position | WindowProperty.Visible
visible: boundToWindow
preferredWidth: 640
preferredHeight: 480
}
attachedObjects: [
MediaPlayer {
id: player
property bool isPlaying: false
sourceUrl: "/accounts/1000/shared/videos/BB10DevAlpha.wmv"
videoOutput: VideoOutput.PrimaryDisplay
windowId: videoSurface.windowId
onMediaStateChanged: {
if (player.mediaState == MediaState.Started) {
console.log("player Started");
playButton.text = "Pause"
isPlaying = true;
} else if (player.mediaState == MediaState.Paused) {
console.log("player Paused");
playButton.text = "Play"
isPlaying = false;
} else if (player.mediaState == MediaState.Stopped) {
console.log("player Stopped");
playButton.text = "Play"
isPlaying = false;
}
}
}
] //attachedObjects
}
}
The code here is playing the source directly from the shared folders (with the "access_shared" permission) just to show how the QML code works. You can obviously use your own CPP function here for getting the absolute path of the packaged video file, if you are playing from there.
I will try to update my Github VideoPlayer sample as soon as possible, to reflect the latest API changes of the Beta 3 SDK (apologies for the delay).
Hope this helps and let us know if you have any further questions (and provide logs, whenever possible
)
Cheers,
Rashid
10-31-2012 06:01 PM
10-31-2012 08:53 PM
Hi Rashid,
Thanks for the info! Glad to see a blue post on this subject ![]()
i already got an app working with the mediaplayer and foreigncontrol in qml, that's how i know it's still bugggy ![]()
Here's a short list of issues i had to fight with:
1) signal onMediaStateChanged -> this rarely ever gets called, and i never saw it called for Started,Stopped, Paused
2) MediaError.SourceUnavailable seems to happen a lot. The same video can work properly and a few minutes later throws this error if tried again. This error is also thrown almost 100% for any video >350s (not sure if related to size or duration or http connection)
3) video/audio seeking does not seem to work (it was in the VideoPlayerSample, but then that was beta2). everytim e a seek is requested, the onPositionChanged does not give the proper position....it simply resets to where the video/audio was at before seeking. (same code as in beta2 videoplayersample was used)
4) calling MediaPlayer.play() in QML seems to freeze the UI thead or the update of ui elements...for example:
playPauseActionItem.imageSource = "images/pause.png" isPlaying=true myPlayer.play();
In the above code snippet, for some reason, my ActionItem never updates itself to the Pause icon but stays as Play icon....this was caused due to calling the play() method. To fix that, i had to use a timer to schedule the play() method call to execute 100ms later... (this smells like some thread synchronisation issues?)
NOTE: i am mostly talking about videos over http (i can pretty much garantee the stability of the video feeds - not streaming, plain 3gp/mp4 files). Local videos are mostly useless ;-)
2 suggestions:
1) Priority should be to update the VideoPlayerSample to BETA3...that would have saved me at least half a day's worth of frustration...
2) better documentation when it comes to error handling
11-01-2012 05:23 PM
Hey lew,
* Thanks for letting us know about these. The issues 1 - 3 *could* be dependent on your network and connectivity, depending on what file you are actually trying to play over the network. Are you just doing progressive download over http?
* Either way, I will try to look into all 4 of them, as time permits. Do you have any code sample/snippets, logs/traces to prove any of these? Those might speed up this process.
* For these 4 issues, it might be worth while if you open up a different forum post or a new item in the developer issue tracker (so that this forum doesn't get trailed and the original poster can close this accordingly).
* With respect to my VideoPlayerSample on github, I will try to update it for Beta 3 within the next few days. That will probably expose and/or fix some of these issues which you might be facing. Apologies for the delay; just been swamped with other work ![]()
Cheers,
Rashid
11-09-2012 12:03 PM - edited 11-09-2012 12:03 PM
Is there documentation related to opening the bound media player? I just searched for half an hour, and found nothing. If there isn't, then can I customize the bound media player? Ex, remove the "Save As" option in the side bar? I'm guessing there isn't. I would love to have "stumbled" upon this 2 weeks ago!
11-09-2012 12:41 PM
@bit-brad,
By"bound" media player, I am assuming you are referring to the media previewer (or "card"), using the invocation framework on BlackBerry 10.
Unfortunately, at this point, It is not possible to modify the UI elements of core media previewer. Since invoking a previewer (a "card") is essentially just invoking a different app, the invoked app would have to support this functionality (and at the moment, this media previewer doesn't).
For now, you can just do the following:
1) invoke it as a separate app - "in app mode"
InvokeRequest cardRequest;
cardRequest.setTarget("sys.mediaplayer.previewer.a pp");
....
2) Or invoke it as a card previewer, embedded within your app (will transition from the right as a new navigation pane)
InvokeRequest cardRequest;
cardRequest.setTarget("sys.mediaplayer.previewer") ;
cardRequest.setUri("file:///accounts/1000/shared/v ideos/BBJamBrazil.mp4");
InvokeManager invokeManager;
invokeManager.invoke(cardRequest);
Yes, it is true that the documentation of the invocation framework may not be complete at the moment (for example: what other previewer apps can be invoked and with what system target ID). I already informed the documentation folks and they are working on it - it should be public in a month or so.
Hope some this helps.
Cheers,
Rashid
11-16-2012 01:37 AM
hello,
I have tried by using your code.. bt I can only listen that video.. Its not getting displayed on foreignwindow control, it shows only black window.. can you please help me to solve this issue ...