Languages

Menu
Sites
Language
Changing media volume by HW media buttons

I play an audio sample in my app but I can't change volume by system HW buttons: up/down.

It doesn't change volume for played media. Is there any function to link app media player

with HW volume buttons? or I have to detect HW buttons events and change on my own?

 

This solution was used in old Tizen and in the same way I can change audio volume for Android apps.

What about Native Tizen?

 

Edited by: Slawek Kowalski on 11 Dec, 2016
View Selected Answer

Responses

2 Replies
Mark as answer
Mango Bar

You have to grab the Key Press Event first. EVAS_CALLBACK_KEY_DOWN  is the key press event. Use following method at the end of create_base_gui method to 
grab the event.

evas_object_event_callback_add(ad->win, EVAS_CALLBACK_KEY_DOWN, on_keydown_cb, ad);

Check the following code

static void
on_keydown_cb(void *data,Evas *evas, Evas_Object *o, void *event_info)
{
    appdata_s *ad = data;
	Evas_Event_Key_Down *ev = event_info;

	char *old_msg = elm_object_text_get(ad->label);
	char total_msg[PATH_MAX];
	char *key_value = strdup(ev->keyname);

	if(strcmp(ev->keyname, "XF86AudioRaiseVolume") == 0)
	{
		key_value = "Volume Up";
	}

	else if(strcmp(ev->keyname, "XF86AudioLowerVolume") == 0)
	{
		key_value = "Volume Down";

	}

	else
	{
		key_value = ev->keyname;
	}

	sprintf(total_msg,"%s<br/>Key Input: [%s]",old_msg,key_value);
	dlog_print(DLOG_INFO,"TAG","Input Key: %s", key_value);
	elm_object_text_set(ad->label,total_msg);
}

static void
create_base_gui(appdata_s *ad)
{
	/* Window */
	/* Create and initialize elm_win.
	   elm_win is mandatory to manipulate window. */
	//Evas_Object *win = NULL;


		ad->win = elm_win_util_standard_add(PACKAGE, PACKAGE);
		elm_win_autodel_set(ad->win, EINA_TRUE);

		if (elm_win_wm_rotation_supported_get(ad->win)) {
			int rots[4] = { 0, 90, 180, 270 };
			elm_win_wm_rotation_available_rotations_set(ad->win, (const int *)(&rots), 4);
		}


	evas_object_smart_callback_add(ad->win, "delete,request", win_delete_request_cb, NULL);
	eext_object_event_callback_add(ad->win, EEXT_CALLBACK_BACK, win_back_cb, ad);


	/* Conformant */
		/* Create and initialize elm_conformant.
		   elm_conformant is mandatory for base gui to have proper size
		   when indicator or virtual keypad is visible. */
		ad->conform = elm_conformant_add(ad->win);
		elm_win_indicator_mode_set(ad->win, ELM_WIN_INDICATOR_SHOW);
		elm_win_indicator_opacity_set(ad->win, ELM_WIN_INDICATOR_OPAQUE);
		evas_object_size_hint_weight_set(ad->conform, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
		elm_win_resize_object_add(ad->win, ad->conform);
		evas_object_show(ad->conform);

		/* Label */
		/* Create an actual view of the base gui.
		   Modify this part to change the view. */
		ad->label = elm_label_add(ad->conform);
		elm_object_text_set(ad->label, "<align=center>Hello Tizen</align>");
		evas_object_size_hint_weight_set(ad->label, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
		elm_object_content_set(ad->conform, ad->label);


	/* Show window after base gui is set up */
	evas_object_show(ad->win);

	evas_object_event_callback_add(ad->win, EVAS_CALLBACK_KEY_DOWN, on_keydown_cb, ad);

}

 

 

you will find the all supported hardware keys event from the following link

https://developer.tizen.org/dev-guide/2.4/org.tizen.ui.practices/html/native/efl/key_grab_n.htm

Slawek Kowalski

Thanks Mango for great answer.