There are many examples of suspended background music on the internet, most of which are broadcast to suspend music according to a paused instruction. In fact, this way is very unreliable, why? Because other players may not register to listen for that broadcast, most of them don't work.
Here's a more reliable way to manipulate the player state by triggering a button on the media.
Copy Code code as follows:
Sendmediabutton (Context,<span style= "Font-size:9pt;line-height:1.5;color: #2B91AF;" >keyevent</span><span style= "font-size:9pt;line-height:1.5;" ". Keycode_media_pause);</span>
Copy Code code as follows:
private static void Sendmediabutton (context context, int keycode) {
KeyEvent keyevent = new KeyEvent (Keyevent.action_down, keycode);
Intent Intent = new Intent (Intent.action_media_button);
Intent.putextra (Intent.extra_key_event, keyevent);
Context.sendorderedbroadcast (Intent,null);
KeyEvent = new KeyEvent (keyevent.action_up, keycode);
Intent = new Intent (Intent.action_media_button);
Intent.putextra (Intent.extra_key_event, keyevent);
Context.sendorderedbroadcast (Intent,null);
}
Another way for a user to realize
Simple to write down the process
{
Private Visualizer visualizer = null;//spectrum tester
Private byte [] mrawvizdata;//Spectrum container
//Instantiated Visualizer object
Visualizer = new Visualizer (0);
Mrawvizdata = new byte[128];
The initialization
if (visualizer!= null) of an object
{
if (visualizer.getenabled ()) {
visualizer.setenabled (false);
}
visualizer.setcapturesize (mrawvizdata.length);/Be sure to use
visualizer.setenabled (true) in the spectral false state; Open Spectrum Access
}
Here's a thread to loop through the spectrum, and I'll just post the fetch.
int status = Visualizer.error;
if (visualizer!= null)
{
//Music spectrum get
status = Visualizer.getfft (Mrawvizdata);//Get Waveform graph
if (status!= visualizer.success)
{
log.i ("Answer", "getwavefail");
}
else
{
int j = 0;
for (int i = 0; i < 128 i++)
{
if (mrawvizdata[i] = = 0)
{
j + +;
}
}
LOG.I ("Answer", "Getwave j =" + j);}}