Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 |
Tags
- Graphic
- Spring
- Menu
- Android
- 생성자
- 메소드
- 국제화
- 이클립스
- struts2
- AWT
- Java
- paint
- 메서드
- oracle
- 안드로이드
- 예외처리
- 오버로딩
- 기본
- OGNL
- JSP
- 클래스
- Eclips
- mybatis
- 전화걸기
- 에러페이지
- JavaScript
- layout
- HTML
- 배열
- 어노테이션
Archives
- Today
- Total
note
Android Video View (동영상 재생) 본문
실행화면 (에뮬레이터 에선 원활히 구동되지 않습니다)
파일 위치
main.xml
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <VideoView android:layout_width="fill_parent" android:layout_height="fill_parent" android:id="@+id/videoView" /> </LinearLayout>
main activity
package net.npaka.videoviewex;
import android.app.Activity;
import android.os.Bundle;
import android.content.Context;
import android.widget.VideoView;
import android.widget.MediaController;
import java.io.InputStream;
import java.io.OutputStream;
//동영상 재생
public class VideoViewEx extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
//비디오 뷰의 생성(1)
VideoView videoView = (VideoView)this.findViewById(R.id.videoView);
videoView.requestFocus();
videoView.setMediaController(new MediaController(this));
try{
/* case1 */
//videoView.setVideoPath("/sdcard/be_my_baby5.mp4");
/* case2 */
//videoView.setVideoURI(
// Uri.parse("http://192.168.200.105:8080/web/be_my_baby5.mp4"));
/* case 3 */
//Raw 자원의 파일 저장(2)
raw2file(this,R.raw.be_my_baby5,"be_my_baby5.mp4");
//동영ㅇ상의 재생 (3)
String path = getFilesDir().getAbsolutePath()+"/be_my_baby5.mp4";
videoView.setVideoPath(path);
videoView.start();
}catch(Exception e){
android.util.Log.e("", e.toString());
}
}
// Raw 자원의 파일 보존
private void raw2file(Context context,
int resID,String fileName) throws Exception {
InputStream in=context.getResources().openRawResource(resID);
in2file(context,in,fileName);
}
// 입력 스트림의 파일 보존
private void in2file(Context context,
InputStream in,String fileName)
throws Exception {
int size;
byte[] w=new byte[1024];
OutputStream out=null;
try {
out=context.openFileOutput(fileName,Context.MODE_WORLD_READABLE);
while (true) {
size=in.read(w);
if (size<=0) break;
out.write(w,0,size);
};
out.close();
in.close();
} catch (Exception e) {
try {
if (in !=null) in.close();
if (out!=null) out.close();
} catch (Exception e2) {
}
throw e;
}
}
}
'Android > 기본' 카테고리의 다른 글
Android 메인로딩 페이지 만들기 (2) | 2012.02.01 |
---|---|
Android surface(마우스에 이미지 따라다니기) (0) | 2012.02.01 |
Android Audio사용 (음악 재생) (0) | 2012.02.01 |
Android Constants Provider (0) | 2012.02.01 |
Android FileSearch Gallery(사진선택) (0) | 2012.02.01 |