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


Thank you for visiting the BlackBerry Support Community Forums.

BlackBerry will be closing the BlackBerry Support Community Forums Device Forums on April 1st (Developers, see below)

BlackBerry remains committed to providing excellent customer support to our customers. We are delighted to direct you to the CrackBerry Forums, a well-established and thorough support channel, for continued BlackBerry support. Please visit http://forums.crackberry.com or http://crackberry.com/ask. You can also continue to visit BlackBerry Support or the BlackBerry Knowledge Base for official support options available for your BlackBerry Smartphone.

"When we launched CrackBerry.com 10 years ago, we set out to make it a fun and useful destination where BlackBerry Smartphone owners could share their excitement and learn to unleash the full potential of their BlackBerry. A decade later, the CrackBerry community is as active and passionate as ever and I know our knowledgeable members and volunteers will be excited to welcome and assist more BlackBerry owners with their questions."

- Kevin Michaluk, Founder, CrackBerry.com

Developers, for more information about the BlackBerry Developer Community please review Join the Conversation on the BlackBerry Developer Community Forums found on Inside BlackBerry.


Reply
Developer
Posts: 83
Registered: ‎06-20-2013
My Device: Blackberry 10
My Carrier: idea
Accepted Solution

play a custom sound on "battery discharge" and "battery full" events

im developing a app to get status of battery..I have used BatteryInfo class for that...i have added a switch case in qml to get status of battery on specific event....now i want to add sound for battery full and battery discharged...

 

Please help

 

Thanks

Developer
Posts: 17,025
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: play a custom sound on "battery discharge" and "battery full" events

Attach a SystemSound object, you can play it by calling its play() method.
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Developer
Posts: 83
Registered: ‎06-20-2013
My Device: Blackberry 10
My Carrier: idea

Re: play a custom sound on "battery discharge" and "battery full" events

[ Edited ]

Thanks but i dont want to play the system sounds...im using mediaplayer for it..i have created mediaplayer object and used it to call play method in my function....and this function is used in switch case of QMl where the battery returns Battery discharging state

 

function in app.cpp

 

void Maxb :: playSound() const
{
m_player->setSourceUrl(QString("asset:///sounds/Doorbell_001.wav"));
m_player->play();
}

 

 

 

accessed it in Qml using setcontextproperty

 

switch (_battery.chargingState) {
case BatteryChargingState.Unknown:
return qsTr("Unknown");
break;
case BatteryChargingState.NotCharging:
return qsTr("Not Charging");
break;
case BatteryChargingState.Charging:
return qsTr("Charging");
// root.playSound("Doorbell_001.wav");
break;
case BatteryChargingState.Discharging:
return qsTr("Discharging");
app.playSound();
break;
case BatteryChargingState.Full:
return qsTr("Full");
break;

 

bt still its not working....

plz suggest

Developer
Posts: 17,025
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: play a custom sound on "battery discharge" and "battery full" events

add debug logging. is the method called? Can you play the sound file from c++?
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Developer
Posts: 83
Registered: ‎06-20-2013
My Device: Blackberry 10
My Carrier: idea

Re: play a custom sound on "battery discharge" and "battery full" events

yes sound can be played through c++,but i want to access it in qml when the battery returns battery discharging state

Developer
Posts: 17,025
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: play a custom sound on "battery discharge" and "battery full" events

if you make the c++ method q_invokable and calling that method works in c++ it also works from qml.
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Developer
Posts: 83
Registered: ‎06-20-2013
My Device: Blackberry 10
My Carrier: idea

Re: play a custom sound on "battery discharge" and "battery full" events

Dont know why,but unfortunately its not working that way.....is it possible to access text of label from QML that returns "discharging" ...so that in cpp we can check if the text is "discharging" then m_player->play();
Developer
Posts: 17,025
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: play a custom sound on "battery discharge" and "battery full" events

looking at your code you return something, then you play the sound.
code after a return is not executed.

yes, you can access the label using findChild, but that would be a new question for a new thread.
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Developer
Posts: 83
Registered: ‎06-20-2013
My Device: Blackberry 10
My Carrier: idea

Re: play a custom sound on "battery discharge" and "battery full" events

yes.but if i call the sound code before return statement then the sound plays on application startup itself and not when the cable is unplugged or  battery is full

Highlighted
Developer
Posts: 83
Registered: ‎06-20-2013
My Device: Blackberry 10
My Carrier: idea

Re: play a custom sound on "battery discharge" and "battery full" events

Thanks i got it......nw its working properly...Smiley Very Happy...

Now is there a way to add a button that can toggle between on/off to play this sound....means if the button is pressed sound will play normally...and if we press it again no sound will be played...

 

Thanks