How to play SystemSounds in the Blackberry 10 Dev Alpha Simulator? - qml

I am just trying to run the provided sample code which, as far as I know, should work just fine. Is there anything I am missing or is this a limitation of the simulator.
If so, are there any workarounds?
import bb.cascades 1.0
// To use the MediaPlayer, we must include
// the multimedia library.
import bb.multimedia 1.0
Page {
Container {
id: mainContainer
layout: StackLayout {
orientation: LayoutOrientation.TopToBottom
}
topPadding: 50.0
Label {
id: titleLbl
text: qsTr("SystemSound and MediaPlayer\n Sample App")
multiline: true
textStyle.fontSizeValue: 9.0
textStyle.fontWeight: FontWeight.Bold
textStyle.fontFamily: "Verdana"
textStyle.color: Color.DarkBlue
textStyle.textAlign: TextAlign.Center
horizontalAlignment: HorizontalAlignment.Center
}
// Part 1 of the sample: Playing system sounds.
Container {
id: systemSoundsContainer
layout: StackLayout {
orientation: LayoutOrientation.TopToBottom
}
topMargin: 100.0
horizontalAlignment: HorizontalAlignment.Center
DropDown {
id: soundSelectorDropdown
title: "Sound: "
maxWidth: 600.0
Option {
text: qsTr("Battery Alarm")
value: SystemSound.BatteryAlarm
selected: true
}
Option {
text: qsTr("Browser Start")
value: SystemSound.BrowserStartEvent
}
Option {
text: qsTr("Camera Shutter")
value: SystemSound.CameraShutterEvent
}
Option {
text: qsTr("Device Tether")
value: SystemSound.DeviceTetherEvent
}
Option {
text: qsTr("General Notification")
value: SystemSound.GeneralNotification
}
} // soundSelectorDropdown
Button {
id: systemSoundPlayButton
text: qsTr("Play Selected System Sound")
minWidth: 600.0
onClicked: {
systemSound.play();
}
} // systemSoundPlayButton
} // systemSoundsContainer
// Part 2 of the sample: Playing custom sound files.
Container {
id: customSoundsContainer
layout: StackLayout {
orientation: LayoutOrientation.LeftToRight
}
topMargin: 100.0
Button {
id: customSoundPlayButton1
text: qsTr("Play Sound 1")
layoutProperties: StackLayoutProperties {
spaceQuota: 1.0
}
onClicked: {
// Here we could have created a second MediaPlayer object to
// use to play our sound, but instead we programmatically
// changed the sourceUrl property of the current myPlayer
// MediaPlayer object, and re-used it to play our sounds.
myPlayer.setSourceUrl("asset:///sounds/Doorbell_001.wav")
myPlayer.play()
}
} // customSoundPlayButton1
Button {
id: customSoundPlayButton2
text: qsTr("Play Sound 2")
layoutProperties: StackLayoutProperties {
spaceQuota: 1.0
}
onClicked: {
// Same as above, here we also could have created a second
// MediaPlayer object to use to play our sound, but instead
// we programmatically changed the sourceUrl property of the
// current myPlayer MediaPlayer object, and re-used it to
// play our sounds.
myPlayer.setSourceUrl("asset:///sounds/Doorbell_002.wav")
myPlayer.play()
}
} // customSoundPlayButton2
} // customSoundsContainer
} // mainContainer
// The SystemSound and MediaPlayer objects are attached so
// they can be used in our QML code to play sounds.
attachedObjects: [
SystemSound {
id: systemSound
sound: soundSelectorDropdown.selectedValue
},
MediaPlayer {
id: myPlayer
// sourceUrl: < Set in the Button control's onClicked event handler. >
}
] // Attached objects.
}
Source: https://developer.blackberry.com/cascades/documentation/design/audio_video/playing_sounds_code_sample.html

I suspect that that System Sounds are actually .mp3 or .ogg files internally, where the "Cowbell sample" and "Pull My Beard" are using .wav files. It's a known issue, and has been discussed on the Blackberry Developer forums here and here, and also here, that the simulator does not have the correct codecs to play any sounds except .wav files. The sounds should play correctly on actual hardware.

Related

QML - change how transition between pages looks

I know this is probably super basic, but I am new to learning QML and have a question about transition between pages.
In this example I have a button with which I want to switch between my 3 pages.
the transition works, but the pages always move from the right-to-the-left-side of the window.
how can I change this? I need the new page to appear as a whole right away.
(e.g. when changing from firstPage to secondPage, for the user it looks like only the AppText changes, because the button is at the same position in both cases)
code example:
App {
id: app
width: px(250); height: px(250)
NavigationStack {
Page {
id: page
navigationBarHidden: true
AppText { text: "startpage" }
SimpleButton{
x: 220; y: 0
onClicked: page.navigationStack.push(firstPage)
}
}
}
Component {
id: firstPage
Page {
navigationBarHidden: true
AppText { text: qsTr("1st page") }
SimpleButton{
x: 220; y: 0
onClicked: page.navigationStack.push(secondPage)
}
}
}
Component {
id: secondPage
Page {
navigationBarHidden: true
AppText { text: qsTr("2nd page") }
SimpleButton{
x: 220; y: 0
onClicked: page.navigationStack.push(page)
}
}
}
}
Any help would be greatly appreciated!
It looks like you're using Felgo, which I think is an extra library on top of Qt. For instance, there is no built-in QML component called NavigationStack. That comes from Felgo. You should mention that in your question to get better help with it.
I've never used Felgo myself, but just looking at the documentation real quick, it looks like you need to define a new transitionDelegate for your needs. Here is the example they give where new pages fade in/fade out.
NavigationStack {
// custom transition delegate
transitionDelegate: StackViewDelegate {
pushTransition: StackViewTransition {
NumberAnimation {
target: enterItem
property: "opacity"
from: 0
to: 1
duration: 1000
}
}
popTransition: StackViewTransition {
NumberAnimation {
target: exitItem
property: "opacity"
from: 1
to: 0
duration: 1000
}
}
}
initialPage: pageComponent
}

Add a contact/pin to BBM from BB 10 Native App

In my BB 10 cascades App , I need to add a Button click listener for Adding a contact information like pin:210000A to Blackberry Messenger (BBM). for that I am doing the following...
main.qml is like
import bb.cascades 1.0
Page {
Container {
layout: DockLayout {
}
TextArea {
id: pinEditor
hintText: "Enter PIN to invite"
onTextChanged: {
inviter.pin = text
}
input.submitKey: SubmitKey.Send
}
Inviter {
id: inviter
horizontalAlignment: HorizontalAlignment.Center
verticalAlignment: VerticalAlignment.Center
}
}
}
and Inviter.qml is like
import bb.cascades 1.0
Container {
property string pin
Button {
text: "Invite to BBM"
onClicked: {
query.uri = "pin:" + pin
invoke.trigger("bb.action.INVITEBBM")
}
}
attachedObjects: [
Invocation {
id: invoke
query: InvokeQuery {
id: query
invokeTargetId: "sys.bbm.sharehandler"
onQueryChanged: {
invoke.query.updateQuery()
}
}
}
but I am getting "Read only property cannot be set"error in Qml.I have also added
LIBS += -lbbplatformbbm
LIBS += -lbbsystem and BBM Permission in "bar-descriptor.xml"
Do I need to Register with BBM for Adding contact in BBM from my App? and how to fix the above error?
Please help,
Thanks
I'm guessing here, but try this way:
Container {
property string pin
Button {
text: "Invite to BBM"
onClicked: {
invoke.query.setUri("pin:" + pin)
invoke.trigger("bb.action.INVITEBBM")
}
}
attachedObjects: [
Invocation {
id: invoke
query {
invokeTargetId: "sys.bbm.sharehandler"
onQueryChanged: {
invoke.query.updateQuery()
}
}
}
]
}

Accessing ListItemComponents on the run

right now I'm trying to create a ListView which loads the dataModel using a custom QML. Here's the snippet of my code:
ListView {
id: firstPageListView
visible: false
dataModel: firstPageDataModel
layout: GridListLayout {
columnCount: 1
cellAspectRatio: 2.0
headerMode: ListHeaderMode.Standard
verticalCellSpacing: 10
}
listItemComponents: [
ListItemComponent {
//custom qml that will be used
ThumbNote {
title: ListItemData.title
text: ListItemData.text
imageSource: ListItemData.image
listmode: true //list mode
date: ListItemData.date
}
}
]
}
I want to create a button that will change the listmode property of each component into false. By doing so, the object will invoke a function that set in the onListModeChanged() of the ThumbNote QML.
Sorry for my poor english, any help would be appreciated. :)
Perhaps you might consider adding a property to the ListView and binding the ThumbNotes' properties to it.
E.g.:
ListView {
id: firstPageListView
visible: true
dataModel: firstPageDataModel
property bool listMode: true
...
listItemComponents: [
ListItemComponent {
//custom qml that will be used
ThumbNote {
title: ListItemData.title
text: ListItemData.text
imageSource: ListItemData.image
listmode: firstPageListView.listMode
date: ListItemData.date
}
}
]
}
Button {
onClicked: {
firstPageListView.listMode = false;
}
}

Dictaphone BB10 in QML

I need make small app on BB10 using QML, which record and play some voice. I have all needed permision (microphone and store file) and this code:
import bb.cascades 1.0
import bb.multimedia 1.0
Page {
property string dataUrl;
Container {
background: Color.create("#001100")
layout: StackLayout {
}
attachedObjects: [
MediaPlayer {
id: audioPlayer
sourceUrl: dataUrl + "/recording.mp4"
},
AudioRecorder {
id: recorder
outputUrl: dataUrl + "/recording.mp4"
}
]
Button {
id: btnRecord
text: "Record"
onClicked: {
recorder.record();
}
}
Button {
id: btnStop
text: "Stop Record"
onClicked: {
recorder.reset();
}
}
Button {
text: "Play Audio"
onClicked: {
audioPlayer.play()
}
}
Button {
text: "Stop Audio"
onClicked: {audioPlayer.stop()
}
}
}
}
After running I can see all buttons, but recording and/or playing is not work. I dont know what is wrong. I cant see any errors.
You're almost there. The problem is your sourceUrl is wrong. The best place to store your recording is in your app's data directory but your QML has no idea where that is.
To solve this you need to expose your app's data path to your QML using C++. You can do this using a property (more info here).
Add the following C++ code under where you create your AbstractPane object (in my case called root). This is normally done in applicationui.cpp.
root->setProperty("dataUrl", "file://" + QDir::currentPath() + "/data");
Now add the dataUrl property to your QML and use it for your sourceUrl:
Page {
property string dataUrl;
Container {
background: Color.create("#001100")
layout: StackLayout {
}
attachedObjects: [
MediaPlayer {
id: audioPlayer
sourceUrl: dataUrl + "/recording.m4a"
},
AudioRecorder {
id: recorder
outputUrl: dataUrl + "/recording.m4a"
}
]
....
}
Edit: Make sure you call audioPlayer.reset() after you've finished recording, this forces the player to reload the recorded audio. If you don't do this your audio playback may be truncated.

Invocation from function in Blackberrry 10 qml?

I have invoked invite to BBM while clicking a button in qml,but i need to send the invitation for the contacts how to do this?my code
Button {
text: "Invite"
onClicked: {
invokeQuery.uri = "pin:210000A"
invokeQuery.updateQuery();
}
attachedObjects: [
Invocation {
id: invokeShare
query: InvokeQuery {
id: invokeQuery
}
onArmed: {
trigger("bb.action.INVITEBBM");
}
}
]
}
Can anyone send me some solutions to solve this.?
Thanks
Invocation query is immutable object which means that values in the query are not dynamic. If you want to update query in dynamic you need to do it via control signals or variables.
For example, you have a component called Inviter with the pin property exposed:
import bb.cascades 1.0
Container {
property string pin
Button {
text: "Invite to BBM"
onClicked: {
query.uri = "pin:" + pin
invoke.trigger("bb.action.INVITEBBM")
}
}
attachedObjects: [
Invocation {
id: invoke
query: InvokeQuery {
id: query
invokeTargetId: "sys.bbm.sharehandler"
onQueryChanged: {
invoke.query.updateQuery()
}
}
}
]
}
Then you can use it this way:
import bb.cascades 1.0
Page {
Container {
layout: DockLayout {
}
TextArea {
id: pinEditor
hintText: "Enter PIN to invite"
onTextChanged: {
inviter.pin = text
}
input.submitKey: SubmitKey.Send
}
Inviter {
id: inviter
horizontalAlignment: HorizontalAlignment.Center
verticalAlignment: VerticalAlignment.Center
}
}
}
Also, don't forget to enable "Blackberry Messenger" permission in your bar-descriptor.xml and add following libraries to your .pro file:
LIBS += -lbbplatformbbm
LIBS += -lbbsystem