본문 바로가기
Programming/Android Java

Galley를 이용한 비디오/이미지 파일 재생에 대한 Intent

by 개Foot/Dog발?! 2014. 8. 27.

URL : http://blog.daum.net/baramjin/16011132


비디오 재생을 위한 파일 브라우져를 만드는 경우 VideoView를 이용하는 새로운 Activity를 만들고 이를 이용하여 Video File을 재생할 수 있다.

 

예를 "video" Activity를 만들고 파일 경로명을 전달받는 intent를 다음과 같이 설계하였다면


public class video extends Activity {

 @Override

 protected void onCreate(Bundle savedInstanceState) {

  // TODO Auto-generated method stub

  .....  

  Intent intent = getIntent();

  String path = intent.getStringExtra("FilePath");

  .....

}


이전 Activiy에서 파일 경로를 전달하는 것은 다음과 같이 한다.


   Intent intent = new Intent(fileplayer.this, video.class);

   intent.putExtra("FilePath", mPath+temp.name);

  

   startActivity(intent);  


이러한 intent를 명시적 intent라고 한다. intent 생성시에 target 클래스를 명확하게 지정하고 있으므로 항상 video 클래스가 시작되고, 여기에서 비디오를 재생하도록 코드를 구현해야 한다.

 

안드로이드의 경우 이미 Gallery, Gallery3D와 같은 비디오 재생 응용 프로그램이 있다.

비디오 재생을 위한 Activity를 별도로 생성하지 않고 Gallery에 포함된 Movie View나 View Image를 사용하려면 암시적 intent를 사용한다.


   Intent intent = new Intent(android.content.Intent.ACTION_VIEW);

   intent.setDataAndType(Uri.parse("file://" + mPath+temp.name), "video/*");

   

   startActivity(intent);  


.....

Galley의 경우 위의 Intent를 실행할 수 있는 Intent filter가 정의되어 있기 때문에 Gallery의 Movie View Activity가 실행되게 된다.

 

Gallery의 AndroidManifest.xml을 파일을 보면 다음과 같다.


        <activity android:name="com.android.camera.MovieView"

.....

             <intent-filter>

                <action android:name="android.intent.action.VIEW" />

                <category android:name="android.intent.category.DEFAULT" />

                <data android:mimeType="video/*" />

                <data android:mimeType="application/sdp" />

             </intent-filter>

.....

        </activity>  


Gallery의 AndroidManifest.xml을 파일을 좀 더 보면 View Image를 사용하기 위한 방법도 알 수 있다.


        <activity android:name="com.android.camera.ViewImage"

.....

            <intent-filter>

                <action android:name="android.intent.action.VIEW" />

                <category android:name="android.intent.category.DEFAULT" />

                <data android:mimeType="image/*" />

            </intent-filter>

        </activity> 

 

즉 위의 코드에서 다음과 같이 수정하면 된다.


   Intent intent = new Intent(android.content.Intent.ACTION_VIEW);

   intent.setDataAndType(Uri.parse("file://" + mPath+temp.name), "image/*");

   

   startActivity(intent);   


.....