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
Posts: 82
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: 16,612
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: 82
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: 16,612
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: 82
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: 16,612
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: 82
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: 16,612
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: 82
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

Developer
Posts: 82
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...:smileyvery-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