您可播放位於程式資源資料夾中的影音資源,也可以播放檔案系統中的影音檔,甚至播放網路上的影音檔案,但方法稍有差異。
播放內部影音資源
MediaPlayer mp =
MediaPlayer.create(context, R.raw.sound_file_1);
mp.prepare();
mp.start();
播放外部影音檔案
MediaPlayer mp = new MediaPlayer();
mp.setDataSource(PATH_TO_FILE);
mp.prepare();
mp.start();
播放網路上的影音檔案
ContentURI myURL = new
ContentURI("http://myserver.com/link/to/my.mp3");
Intent intent = new
Intent(Intent.VIEW_ACTION, myURL);
intent.setType("audio/*");
startActivity(intent);
擷取畫面
Bitmap
copyWindowBitmap()
Return
a copy of the bitmap holding the overall contents of the window this view is
attached to.
void
getAbsoluteLocationOnScreen(int[] location)
Computes
the coordinates of this view on the screen.
錄音與錄影
1. 啟動錄製功能
recorder = new MediaRecorder();
ContentValues values = new ContentValues(3);
values.put(Video.MediaColumns.TITLE, SOME_NAME_HERE);
values.put(Video.MediaColumns.TIMESTAMP, System.currentTimeMillis());
values.put(Video.MediaColumns.MIME_TYPE, recorder.getMimeContentType());
contentResolver = new ContentResolver();
ContentURI base = Video.Media.INTERNAL_CONTENT_URI;
ContentURI newUri = contentResolver.insert(base, values);
if (newUri == null) {
// need to handle exception here - we were not able to create a new
// content entry
}
String path = contentResolver.getDataFilePath(newUri);
// could use setPreviewDisplay() to display a preview to suitable View
here
recorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
recorder.setVideoSize(176, 144); // QCIF
recorder.setVideoFrameRate(15);
recorder.setVideoEncoder(MediaRecorder.VideoEncoder.H263);
recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
recorder.setOutputFile(path);
recorder.prepare();
recorder.start();
2. 停止錄製功能
recorder.stop();
recorder.release();
照相功能
推薦給同仁
您想要瞭解更多的免費小竅門以便提升你的網站排名嗎?
請馬上聯繫我們網站管理員:
MSN: chenlinwu@cmmail.com
Email: info@rank-ad.com