电话不显示我的视频播放器名称来播放视频

时间:2015-04-03 10:58:42

标签: android

我开发了一个Android视频播放器并在res / drawable文件夹中放置了一个视频作为默认视频。

然后在我点击任何视频后在手机中安装.apk后,我的手机显示已安装的媒体播放器列表来播放视频,但我的播放器不在列表中。

XML:

<?xml version="1.0" encoding="utf-8"?> 
<FrameLayout xmlns:android="schemas.android.com/apk/res/android"; android:layout_width="fill_parent"
 android:layout_height="fill_parent" 
android:layout_gravity="center" >
 <VideoView android:id="@+id/video_view" 
android:layout_width="match_parent" 
android:layout_height="wrap_content" 
android:layout_gravity="center"/>
 </FrameLayout>

代码

 @Override protected void onCreate(final Bundle savedInstanceState) { 
super.onCreate(savedInstanceState); // set the main layout of the activity 
 setContentView(R.layout.activity_main); //set the media controller buttons 
    if(mediaControls == null)
     { mediaControls = new MediaController(AndroidVideoViewExample.this);
     } //initialize the VideoView 
     myVideoView = (VideoView) findViewById(R.id.video_view); 
    } 

我该怎么办?

1 个答案:

答案 0 :(得分:0)

If you want the Android to know that your App can play videos and add it to the list of suggested Apps when the user clicks on any video, you need to add an intent in your Android Manifest. This sample code will let the OS know that your app can be used as a Media Player that can accept video files. Also, the MyActivity will be launched when the user chooses to play the video with your app.

    <activity android:name=".ui.MyActivity" >
    <intent-filter>
        <category android:name="android.intent.action.MAIN" /> <!--  If this is the main activity -->
        <action android:name="android.intent.action.MUSIC_PLAYER" />
        <action android:name="android.intent.category.APP_MUSIC" />
        <data android:mimeType="video/*" /> <!-- To make sure we let Android know that we accept video -->
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />

    </intent-filter>
    </activity>

参考:How to tag video player for opening video files from other apps?