android development app development files open procedure codes for yourself

android development in their own player MP4 file open way to choose their own development app implementation steps. Red important specific method

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="activiity.date.gfonda.com.fonda">

    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.RECORD_AUDIO" />
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
    <uses-feature
        android:name="android.hardware.touchscreen"
        android:required="false" />
    <uses-feature
        android:name="android.software.leanback"
        android:required="true" />

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:theme="@style/Theme.Leanback">
        <activity
            android:name=".MainActivity"
            android:banner="@mipmap/ic_launcher"
            android:icon="@mipmap/ic_launcher"
            android:label="@string/app_name"
            android:logo="@mipmap/ic_launcher"
            android:screenOrientation="landscape">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                 <category android:name="android.intent.category.LAUNCHER" />

            </intent-filter>
            <intent-filter>
                <action android:name="android.intent.action.VIEW"></action>
                <category android:name="android.intent.category.DEFAULT"></category>
                <data android:mimeType="video/mp4"></data>
            </intent-filter>

        </activity>

    </application>

</manifest>

  

/*
 * Copyright (C) 2014 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
 * in compliance with the License. You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software distributed under the License
 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
 * or implied. See the License for the specific language governing permissions and limitations under
 * the License.
 */

package activiity.date.gfonda.com.fonda;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.Intent;
import android.database.Cursor;
import android.media.MediaPlayer;
import android.net.Uri;
import android.os.Bundle;
import android.provider.MediaStore;
import android.widget.MediaController;
import android.widget.VideoView;

/*
 * MainActivity class that loads MainFragment
 */
public class MainActivity extends Activity {
    /**
     * Called when the activity is first created.
     */
    private String videopath;
    private VideoView videoview;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.mainactivity);

        videoview=findViewById(R.id.videoView2);


        Intent intent = getIntent();
        String action = intent.getAction();//action
        String type = intent.getType();//类型

        if (Intent.ACTION_VIEW.equals(action) && type != null && "video/mp4".equals(type)) {

           // Uri uri = (Uri) intent.getParcelableExtra(Intent.EXTRA_STREAM);
            //如果是媒体类型需要从数据库获取路径
            //String filePath=getRealPathFromURI(uri);
            Uri uri = intent.getData();
            String str = getRealPathFromURI(uri);
//            AlertDialog.Builder builder  = new AlertDialog.Builder(MainActivity.this);
//            builder.setTitle("确认" ) ;
//            builder.setMessage(str) ;
//            builder.setPositiveButton("是" ,  null );
//            builder.show();
            videoview.setVideoPath(str);
        }else {

        videopath="file:///android_asset/sp.mp4";

        //videoview.setVideoPath(videopath);

        String uris = "android.resource://" + getPackageName() + "/" + R.raw.sp;
     //  String uri="";
        videoview.setVideoPath(uris);
        }
        videoview.requestFocus();
        //创建MediaController对象
        MediaController mediaController = new MediaController(this);
        videoview.setMediaController(mediaController);
        videoview.start();
        // Listen video finishes playing code
        videoview.setOnCompletionListener (new new MediaPlayer.OnCompletionListener () { 

            @Override 
            public void onCompletion (the MediaPlayer MPlayer) { 
                // the TODO Auto-Generated Method Stub 
                mPlayer.start (); 
                mPlayer.setLooping (to true); 
            } 
        }); 
    } 
    / ** 
     * acquisition in real path of the local storage file by Uri 
     * / 
        String [] MediaStore.MediaColumns.DATA proj = {}; 
        . = getContentResolver the Cursor Cursor () Query (contentURI, proj, null, null, null); 
        IF (Cursor. MoveToNext ()) { 
            return cursor.getString (cursor.getColumnIndex (MediaStore.MediaColumns.DATA));
     Private String getRealPathFromURI (Uri contentURI) {
        }
        cursor.close();
        return null;
    }
}

  

 

Guess you like

Origin www.cnblogs.com/woaijingjing/p/11127590.html