When writing a program, we will use the following code to notify the sound to implement this behavior:
Setvolumecontrolstream (audiomanager. stream_music );
Mediaplayer = new mediaplayer ();
Mediaplayer. setaudiostreamtype (audiomanager. stream_music );
// Mediaplayer. setoncompletionlistener (beeplistener );
Assetfiledescriptor file = getresources (). openrawresourcefd (R. Raw. Beep );
Try {
Mediaplayer. setdatasource (file. getfiledescriptor (), file. getstartoffset (),
File. getlength ());
File. Close ();
Mediaplayer. setvolume (beep_volume, beep_volume );
Mediaplayer. Prepare ();
} Catch (ioexception e ){
Mediaplayer = NULL;
}
Mediaplayer. Start ();
The following code uses the system vibration:
/Prompt
Vibrator = (vibrator) getsystemservice (vibrator_service );
Long [] pattern = {800, 50,400, 30}; // off/On/Off/on...
Vibrator. vibrate (pattern, 2); //-1 is not repeated, and non-1 is repeated starting from the specified subscript of Pattern
The system volume has the following parameters:
136/** the audio stream for system sounds */
137 public static final int stream_system = audiosystem. stream_system;
138/** the audio stream for the phone ring */
139 public static final int stream_ring = audiosystem. stream_ring;
140/** the audio stream for music playback */
141 public static final int stream_music = audiosystem. stream_music;
If you want to use the progress box for adjustment, you can use the following code:
Mediaplayer MP
=
Mediaplayer. Create (context, R. Raw. Recv );
MP. setaudiostreamtype (audiomanager. stream_music );
Int
Maxvolume
=
Maudiomanager. getstreammaxvolume (audiomanager. stream_music );
MP. setvolume (maxvolume
*
Mlastprogress
/
10
, Maxvolume
*
Mlastprogress
/
10
);
Audiomanager maudiomanager
=
(Audiomanager) Context. getsystemservice (context. audio_service );
Maudiomanager. setstreamvolume (audiomanager. stream_music, maxvolume
*
Mlastprogress
/
10
,
0
);