Android 多媒体开发相关技巧
2010-02-26 01:41:00 来源:WEB开发网AudioTrack.java:SoundPool.java 播放android application的生音资源。
AudioRecord.java: 为android applicatio 提供录音设置(sample、chanel等)的接口;
简单的例子:
播放一个文件:
MediaPlayer mp = new MediaPlayer();
mp.setDataSource(“/sdcard/test.mp3”);
mp.prepare();
mp.start();
播放raw resouce
MediaPlayer mp = MediaPlayer.create(context, R.raw.sound_file_1);
mp.start();
录音:
MediaRecorder recorder = new MediaRecorder();
recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
recorder.setOutputFile(“/sdcard/test.amr”);
recorder.prepare();
recorder.start();
...
alarmclock 调用Media 的基本过程:
...
mMediaPlayer = new MediaPlayer();
mMediaPlayer.setVolume(IN_CALL_VOLUME, IN_CALL_VOLUME);
// 检查是否是在通话中,若是,就换用较小的声音提示。
if (tm.getCallState() != TelephonyManager.CALL_STATE_IDLE) {
Log.v("Using the in-call alarm");
mMediaPlayer.setVolume(IN_CALL_VOLUME, IN_CALL_VOLUME);
setDataSourceFromResource(context.getResources(),
mMediaPlayer, R.raw.in_call_alarm);
}
else
{
mMediaPlayer.setDataSource(context, Uri.parse(mAlert));
}
mMediaPlayer.setAudioStreamType(AudioManager.STREAM_ALARM);
mMediaPlayer.setLooping(true);
mMediaPlayer.prepare();
mMediaPlayer.prepare();
...
Android 多媒体相关技巧二(FrameWork相关)
1、./frameworks/base/media/jni
JAVA本地调用部分。编译后生成的目标是libmedia_jni.so.
android_media_MediaPlayer.cpp: MediaPlayer 的JAVA本地调用部分。
更多精彩
赞助商链接