A way to control the default Android media player from my own service (pause/play/..)

maiconcwb

Member
Licensed User
Longtime User
Hi friends,

I'm looking for a way to control the default Android media player from my own service (or activity). :sign0085: I'm NOT interested in playing media from my service or activity, I'd like to do pause/play/stop/next/previous operations (maybe using Intents??) and, if possible, read track name and other information from the current song being played.

Thanks in advance! :)

P.S. Sorry my english...
 

NeoTechni

Well-Known Member
Licensed User
Longtime User
When I click play:

No configuration file: /system/etc/customization/settings/com/sonyericsson/textinput/uxp/custom_settings.xml


Starting MediaPlaybackServiceImpl.


Remote Control registerMediaButtonEventReceiver() for ComponentInfo{com.sonyericsson.music/com.sonyericsson.music.playbackservice.MediaButtonReceiver}


Play song: /mnt/sdcard/media/music/To_Aru_Kagaku_no_Railgun_-_Only_My_Railgun.mp3


AudioFocus requestAudioFocus() from android.media.AudioManager@2afe3278com.sonyericsson.music.playbackservice.MediaPlaybackServiceImpl$1@2afdb648
DrmManager::eek:penDecryptSession: no capable plug-in found


NULL decryptHandle is returned
no decryptHandle is generated in service side
Play song: /mnt/sdcard/media/music/To_Aru_Kagaku_no_Railgun_-_Only_My_Railgun.mp3


AudioFocus requestAudioFocus() from android.media.AudioManager@2afe3278com.sonyericsson.music.playbackservice.MediaPlaybackServiceImpl$1@2afdb648
Routing audio to Speakerphone


set_light_attention: color=0x00ffffff, mode=2
value of device and enable is 6 1
[292112.048919] [msm7x30.c:msm_device_put] device speaker_stereo_rx set 1
[292112.048950] [msm7x30.c:msm_device_put] device freq =48000
[292112.061614] [adsp.c:msm_adsp_get] module AFETASK has been registered


[292112.061614] [adsp.c:msm_adsp_enable] enable 'AFETASK'state[0] id[17227119]
set_light_attention: color=0x00000000, mode=0
[292112.085510] [adsp.c:adsp_rtos_mtoa_cb] rpc event=0, proc_id=2, module=17227119, image=0
[292112.085510] [adsp.c:adsp_rtos_mtoa_cb] module AFETASK: READY


[292112.130218] msm_snddev_poweramp_on: power on amplifier


[292112.130279] [adsp.c:msm_adsp_get] module AUDPPTASK has been registered
[292112.130310] [adsp.c:msm_adsp_enable] enable 'AUDPPTASK'state[0] id[17227122]
write blocked for 93 msecs, 53 delayed writes, thread 0x11290
[292112.140197] [adsp.c:adsp_rtos_mtoa_cb] rpc event=0, proc_id=2, module=17227122, image=0
[292112.140228] [adsp.c:adsp_rtos_mtoa_cb] module AUDPPTASK: READY
[292112.144165] [audpp.c:audpp_dsp_event] ENABLE
[292112.148345] [adsp.c:msm_adsp_write] AUDPPTASK command took 69 attempts: rc 0
[292112.148376] [audio_acdb.c:acdb_fill_audpp_cal_gain] unable to find audpp calibration gain block returning
GC_EXPLICIT freed 317K, 54% free 2811K/6087K, external 1750K/2133K, paused 116ms

When I click next track:
Starting MediaPlaybackServiceImpl.


DrmManager::eek:penDecryptSession: no capable plug-in found


NULL decryptHandle is returned
no decryptHandle is generated in service side


Play song: /mnt/sdcard/media/music/To_Aru_Kagaku_no_Railgun_-_Only_My_Railgun.mp3
AudioFocus requestAudioFocus() from android.media.AudioManager@2afe3278com.sonyericsson.music.playbackservice.MediaPlaybackServiceImpl$1@2afdb648

When I click previous:
Starting MediaPlaybackServiceImpl.

I also found this:
http://stackoverflow.com/questions/6352136/android-using-intents-to-control-media-player

And emailed the developer of widgetsoid. I'll tell you if I figure anything out
 
Last edited:
Upvote 0

NeoTechni

Well-Known Member
Licensed User
Longtime User
B4X:
long eventtime = SystemClock.uptimeMillis();

  Intent downIntent = new Intent(Intent.ACTION_MEDIA_BUTTON, null);
  KeyEvent downEvent = new KeyEvent(eventtime, eventtime,
KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE, 0);
  downIntent.putExtra(Intent.EXTRA_KEY_EVENT, downEvent);
  sendOrderedBroadcast(downIntent, null);

  Intent upIntent = new Intent(Intent.ACTION_MEDIA_BUTTON, null);
  KeyEvent upEvent = new KeyEvent(eventtime, eventtime,
KeyEvent.ACTION_UP, KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE, 0);
  upIntent.putExtra(Intent.EXTRA_KEY_EVENT, upEvent);
  sendOrderedBroadcast(upIntent, null);

We just need to convert that to B4A

But our intent object doesnt support Intent.ACTION_MEDIA_BUTTON
So you need to make a new topic asking Erel to add it.
 
Last edited:
Upvote 0

maiconcwb

Member
Licensed User
Longtime User
Thanks for fast replay!!

I'm new in android world, I dont't understand very well about intent, but I could do something:

Dim i As Intent
Dim p As Phone
i.Initialize("com.android.music.musicservicecommand","")
i.PutExtra("command", "togglepause")
Try
p.SendBroadcastIntent(i)
Catch
ToastMessageShow("Sorry, something wrong...", True)
End Try

...and it works! :icon_clap: (with player already open)

You can use stop/pause/previous/next.

Now, i have 50%, just need get current song name... possible?

thanks again!
 
Upvote 0
Top