01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
20
|
MediaPlayer mediaPlayer = newMediaPlayer();
if
(mediaPlayer.isPlaying()) {
mediaPlayer.reset();
//重置为初始状态
}
mediaPlayer.setDataSource(
"/sdcard/good.mp3"
);
mediaPlayer.prepare();
//缓冲
mediaPlayer.start();
//开始或恢复播放
mediaPlayer.pause();
//暂停播放
mediaPlayer.start();
//恢复播放
mediaPlayer.stop();
//停止播放
mediaPlayer.release();
//释放资源
mediaPlayer.setOnCompletionListener(newMediaPlayer.OnCompletionListener() {
public
void
onCompletion(MediaPlayer arg0) {
//播放完毕调用
mediaPlayer.release();
} });
mediaPlayer.setOnErrorListener(newMediaPlayer.OnErrorListener() {
// 错误处理事件
public
boolean
onError(MediaPlayer player,
int
arg1,
int
arg2) {
mediaPlayer.release();
returnfalse;
} });
|
01
02
03
04
05
06
07
08
09
10
11
|
/* 创建VideoView对象 */
final VideoView videoView = (VideoView)findViewById(R.id.VideoView01);
/*设置视频路径*/
videoView.setVideoPath("/sdcard/test.mp4");
/* 设置模式-播放进度条 */
videoView.setMediaController(new MediaController(Activity01.this));
videoView.requestFocus();
/* 开始播放 */
videoView.start();
/* 暂停 */
videoView.pause();
|
1
2
|
<
uses-permission
android:name
=
"android.permission.RECORD_AUDIO"
/>
<
uses-permission
android:name
=
"android.permission.WRITE_EXTERNAL_STORAGE"
/>
|
01
02
03
04
05
06
07
08
09
10
11
|
MediaRecorder recorder = newMediaRecorder();
recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
//从麦克风采集声音
recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
//内容输出格式
recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
//音频编码方式
recorder.setOutputFile(
"/sdcard/lxt008.amr"
);
recorder.prepare();
//预期准备
recorder.start();
//开始刻录
...
recorder.stop();
//停止刻录
recorder.reset();
//重设
recorder.release();
//刻录完成一定要释放资源
|
1
2
|
<
uses-permission
android:name
=
"android.permission.RECORD_AUDIO"
/>
<
uses-permission
android:name
=
"android.permission.CAMERA"
/>
|
01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
|
WindowManager wm = (WindowManager)getSystemService(Context.WINDOW_SERVICE);
//获取窗口服务
Display display =wm.getDefaultDisplay();
//获取屏幕信息
recorder =
new
MediaRecorder();
recorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
//从照相机采集视频
recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
recorder.setVideoSize(display.getWidth(),display.getHeight());
//大小为屏幕的宽和高
recorder.setVideoFrameRate(
3
);
//每秒3帧
recorder.setVideoEncoder(MediaRecorder.VideoEncoder.H263);
//设置视频编码方式
recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
recorder.setOutputFile(
"/sdcard/lxt008.3gp"
);
recorder.prepare();
//预期准备
recorder.start();
//开始刻录
...
recorder.stop();
//停止刻录
recorder.reset();
//重设
recorder.release();
//刻录完成一定要释放资源
|
01
02
03
04
05
06
07
08
09
10
11
|
//打开系统铃声设置
Intent intent = newIntent(RingtoneManager.ACTION_RINGTONE_PICKER);
//设置铃声类型和title
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_TYPE,RingtoneManager.TYPE_RINGTONE);
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_TITLE,“设置来电铃声");
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_TYPE,RingtoneManager.TYPE_ALARM);
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_TITLE,
"设置闹铃铃声"
);
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_TYPE,RingtoneManager.TYPE_NOTIFICATION);
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_TITLE,
"设置通知铃声"
);
//当设置完成之后返回到当前的Activity
startActivityForResult(intent,ButtonAlarm);
|
1
2
3
4
5
6
7
8
9
|
/* 当设置铃声之后的回调函数 */
protected
void
onActivityResult(intrequestCode,
int
resultCode, Intent data){
//得到我们选择的铃声
Uri pickedUri =data.getParcelableExtra(RingtoneManager.EXTRA_RINGTONE_PICKED_URI);
//将我们选择的铃声设置成为默认
RingtoneManager.setActualDefaultRingtoneUri(Activity01.
this
,RingtoneManager.TYPE_RINGTONE, pickedUri);
Uri pickedUri =RingtoneManager.setActualDefaultRingtoneUri(Activity01.
this
,RingtoneManager.TYPE_ALARM, pickedUri);
RingtoneManager.setActualDefaultRingtoneUri(Activity01.
this
,RingtoneManager.TYPE_NOTIFICATION, pickedUri);
}
|
01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
20
21
|
<
LinearLayout
xmlns:android
=
"http://schemas.android.com/apk/res/android"
android:orientation
=
"vertical"
android:layout_width
=
"fill_parent"
android:layout_height
=
"fill_parent"
>
<
TextView
android:id
=
"@+id/TextView01"
android:layout_width
=
"fill_parent"
android:layout_height
=
"wrap_content"
android:text
=
"选择下面按钮来设置铃声"
/>
<
Button
android:id
=
"@+id/ButtonRingtone"
android:layout_width
=
"fill_parent"
android:layout_height
=
"wrap_content"
android:text
=
"设置来电铃声"
/>
<
Button
android:id
=
"@+id/ButtonAlarm"
android:layout_width
=
"fill_parent"
android:layout_height
=
"wrap_content"
android:text
=
"设置闹钟铃声"
/>
<
Button
android:id
=
"@+id/ButtonNotification"
android:layout_width
=
"fill_parent"
android:layout_height
=
"wrap_content"
android:text
=
"设置通知铃声"
/>
</
LinearLayout
>
|
01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
|
<
manifest
xmlns:android
=
"http://schemas.android.com/apk/res/android"
[/align]
package
=
"com.yarin.android.Examples_07_08"
android:versionCode
=
"1"
android:versionName
=
"1.0"
>
<
application
android:icon
=
"@drawable/icon"
android:label
=
"@string/app_name"
>
<
activity
android:name
=
".Activity01"
android:label
=
"@string/app_name"
>
<
intent-filter
>
<
action
android:name
=
"android.intent.action.MAIN"
/>
<
category
android:name
=
"android.intent.category.LAUNCHER"
/>
</
intent-filter
>
</
activity
>
</
application
>
<
uses-permission
android:name
=
"android.permission.INTERNET"
/>
<
uses-permission
android:name
=
"android.permission.MOUNT_UNMOUNT_FILESYSTEMS"
/>
<
uses-sdk
android:minSdkVersion
=
"7"
/>
</
manifest
>
|