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
New Contributor
grotta
Posts: 6
Registered: ‎08-23-2013
My Carrier: Entel

Connect hardware volume to slider

Hi, I'm working in a radio app, and I already have play/pause button and a slider for volume, but I need to connect the hardware volume up and down to the slider.

 

The MediaKeyWatcher is not useful here, since the watcher eats the signal so the volume don't get up or down. 

 

I'm using C++ audiomixer_get_output_level and audiomixer_set_output_level to get and set the volume using the slider. 

 

I also have a Media Player and a NowPlayingConnection to show a fancy controls.

 

Thanks for your help.

 

 

Please use plain text.
BlackBerry Development Advisor
mwoolley
Posts: 559
Registered: ‎06-25-2010
My Carrier: Vodafone

Re: Connect hardware volume to slider

Hi

 

I think you should be able to achieve your goal by using the audio_manager_status_volume_change_t audio management event type:

 

https://developer.blackberry.com/native/reference/core/com.qnx.doc.audiomanager.lib_ref/topic/struct...

 

I have a simple sample app showing how to use audio management events in case you're unfamiliar with this API:

 

https://github.com/blackberry/Cascades-Community-Samples/tree/master/AudioManagerEvents

 

Hope this help

 

Martin

--------------------------------------------------------------------------------------------
Feel free to press the like button on the right side if you liked my attempts to help :-)
And please mark posts as solved if you think I found the solution or set you on its path. Thanks!
Follow me on Twitter: @mdwrim
Please use plain text.
New Contributor
grotta
Posts: 6
Registered: ‎08-23-2013
My Carrier: Entel

Re: Connect hardware volume to slider

Hi, thanks for your help, at the end, I made it using bps and a StatusEventHandler class. 

 

#include "StatusEventHandler.h"
#include <bps/bps.h>
#include <bps/audiomixer.h>

StatusEventHandler::StatusEventHandler() {
	subscribe(audiomixer_get_domain());
	bps_initialize();
	audiomixer_request_events(0);
}

StatusEventHandler::~StatusEventHandler() {
	bps_shutdown();
}

void StatusEventHandler::event(bps_event_t *event) {

	if (bps_event_get_domain(event) == audiomixer_get_domain()) {

		float speaker_volume;
		audiomixer_get_output_level(AUDIOMIXER_OUTPUT_DEFAULT, &speaker_volume);

		emit mixerUpdated(speaker_volume);
	}

}


#ifndef STATUSEVENTHANDLER_H_
#define STATUSEVENTHANDLER_H_

#include <QObject>
#include <QString>
#include <bb/AbstractBpsEventHandler>

class StatusEventHandler: public QObject, public bb::AbstractBpsEventHandler {
    Q_OBJECT

public:
    StatusEventHandler();
    virtual ~StatusEventHandler();
    virtual void event(bps_event_t *event);

signals:
	void mixerUpdated(float volume);
};

#endif /* STATUSEVENTHANDLER_H_ */

 and in the applicationui.cpp

 

statusEventHandler = new StatusEventHandler();
	connect(statusEventHandler, SIGNAL(mixerUpdated(float)), this,SLOT(mixerUpdateHandler(float)));

.....

AbstractPane *root = qml->createRootObject<AbstractPane>();
volumeSlider = root->findChild<Slider*>("volumeslider");

....

void ApplicationUI::mixerUpdateHandler(float volume) {
	volumeSlider->setValue(volume);
}

 and in the applicationui.hpp

private slots:
void mixerUpdateHandler(float volume);

private:
    bb::cascades::Slider *volumeSlider;
    StatusEventHandler  *statusEventHandler;

 

 

Please use plain text.
BlackBerry Development Advisor
mwoolley
Posts: 559
Registered: ‎06-25-2010
My Carrier: Vodafone

Re: Connect hardware volume to slider

OK, so if there's a BPS audio mixer event. you assume it's a volume control change. Great! :-)

--------------------------------------------------------------------------------------------
Feel free to press the like button on the right side if you liked my attempts to help :-)
And please mark posts as solved if you think I found the solution or set you on its path. Thanks!
Follow me on Twitter: @mdwrim
Please use plain text.