확인단말 : GalaxyNexus, Galaxy S2


Galaxy Nexus에서 좀처럼 동영상을 재생해주지않아서 삽질.


raw리소스의 동영상 파일을 file로 출력한 후, 생성파일을 이용해서 재생.

생성화일의 확장자는 관계없었다. (mp4를 mov로 바꾸어도 재생가능)


a() : 안드로이드에서 제공해주는 ACTION_VIEW 이용.

b() : VideoView + MediaController 이용.



방법1. 갤러리 이용


void a(){


this.filecopy();

String path = getFilesDir().getAbsolutePath()+"/"+FILE_NAME;

Log.e(null, path);

Log.e(null, "file exist? "+ new File(path).exists());


Intent i = new Intent(Intent.ACTION_VIEW);

 


Uri uri = Uri.fromFile(new File(path));

  it.setDataAndType(uri, "video/*");

  startActivity(i);

}


방법2. VideoVIew



void b(){


VideoView vv = (VideoView) findViewById(R.id.videoView1);


MediaController mc = new MediaController(this);

mc.setAnchorView(vv);

this.filecopy();

String path = getFilesDir().getAbsolutePath()+"/"+FILE_NAME;

Log.e(null"xxx : "+path);

Log.e(null"file : "+new File(path).exists());

vv.setMediaController(mc);

//Uri uri = Uri.fromFile(new File(path));

//vv.setVideoURI(uri);  //uri로도 정상동작

vv.setVideoPath(path);

vv.requestFocus();

vv.start();

}




raw Resource -> file


final String FILE_NAME = "a1.mp4";


void filecopy() {


Log.e(null, "filecopy");

InputStream in = this.getResources().openRawResource(R.raw.a14); //raw리소스


int size;

byte[] w = new byte[1024];

OutputStream out = null;

try {

out = this.openFileOutput(FILE_NAME, 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) {

Log.e(null, e.toString());

}


}


Posted by tenn
,