如何在Blackberry中播放视频文件

时间:2014-06-25 07:19:06

标签: video blackberry blackberry-10 playback

我是BlackBerry Development的新手。现在我想在我的Blackberry Application中播放一个视频文件。现在播放器将显示如下,

enter image description 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: "asset:///Videos/instruction.mp4"
                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
    }
}

现在点击播放按钮时,它将显示为图像

0 个答案:

没有答案