Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Native Development

Reply
Developer
raju504
Posts: 86
Registered: ‎05-21-2012
My Device: Blackberry 10 Dev Alpha
My Carrier: IDEA
Accepted Solution

Cannot play a video using QML code

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

- Raju
Please use plain text.
Developer
ekke
Posts: 1,504
Registered: ‎04-08-2010
My Device: Z10 (red Limited Edition), Q10, Z30
My Carrier: Telekom.de, O2, Vodafone

Re: Cannot play a video using QML code

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

-------------------------------------------------------------------------------
ekke (independent software architect, rosenheim, germany)

BlackBerry Elite Developer
International Development Mobile Apps BlackBerry 10 Cascades
Cascades - Workshops / Trainings / Bootcamps

Open Source Enthusiast
blog: http://ekkes-corner.org videos: http://www.youtube.com/user/ekkescorner
bb10-development: http://appbus.org Twitter: @ekkescorner
Please use plain text.
Developer
Developer
lew
Posts: 174
Registered: ‎03-05-2009
My Device: Dev Alpha
My Carrier: -

Re: Cannot play a video using QML code

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?

Please use plain text.
BlackBerry Development Advisor (Retired)
s_rashid
Posts: 127
Registered: ‎02-27-2012
My Device: Bold
My Carrier: Rogers

Re: Cannot play a video using QML code

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 :smileyhappy: )

 

Cheers,

Rashid

Please use plain text.
BlackBerry Development Advisor (Retired)
s_rashid
Posts: 127
Registered: ‎02-27-2012
My Device: Bold
My Carrier: Rogers

Re: Cannot play a video using QML code

Hello lew,

Yes, there are a couple of known limitations/bugs at the moment, in the MediaPlayer API of Beta 3 SDK and I have already forwarded them to the development teams. Other than those, the QML way of doing the media playback is actually very simple (for example: you can take a look at my first reply in this thread, to the original poster).

If you have any particular bugs that you know of or any other suggestions, feel free to let us know. It might help the development teams to improve the API :smileyhappy:

For example, in Beta 3, some of the known issues of the MediaPlayer API are:

* The fact that it requires the absolute path as an input
* Supporting .m3u
Please use plain text.
Developer
Developer
lew
Posts: 174
Registered: ‎03-05-2009
My Device: Dev Alpha
My Carrier: -

Re: Cannot play a video using QML code

Hi Rashid,

 

Thanks for the info! Glad to see a blue post on this subject :smileyhappy:

i already got an app working with the mediaplayer and foreigncontrol in qml, that's how i know it's still bugggy :smileyhappy:

 

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

 

Please use plain text.
BlackBerry Development Advisor (Retired)
s_rashid
Posts: 127
Registered: ‎02-27-2012
My Device: Bold
My Carrier: Rogers

Re: Cannot play a video using QML code


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 :smileyhappy:

Cheers,

Rashid

Please use plain text.
Contributor
bit-brad
Posts: 31
Registered: ‎11-02-2012
My Device: Dev Alpha
My Carrier: None

Re: Cannot play a video using QML code

[ Edited ]

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!

Please use plain text.
BlackBerry Development Advisor (Retired)
s_rashid
Posts: 127
Registered: ‎02-27-2012
My Device: Bold
My Carrier: Rogers

Re: Cannot play a video using QML code

@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.app");
....

 

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/videos/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

Please use plain text.
Contributor
Sneha_Junagade
Posts: 14
Registered: ‎07-31-2012
My Device: 9790
My Carrier: airtel

Re: Cannot play a video using QML code

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  ...

Please use plain text.