博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
android 开发 文件打开为自己开发app操作步骤代码
阅读量:5339 次
发布时间:2019-06-15

本文共 3774 字,大约阅读时间需要 12 分钟。

android开发中 自己播放器  MP4文件打开方式选择自己开发app实现步骤。红色重要具体实现方法

  

/* * 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();        //监听视频播放完的代码        videoview.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {            @Override            public void onCompletion(MediaPlayer mPlayer) {                // TODO Auto-generated method stub                mPlayer.start();                mPlayer.setLooping(true);            }        });    }    /**     * 通过Uri获取文件在本地存储的真实路径     */    private String getRealPathFromURI(Uri contentUri) {        String[] proj = {MediaStore.MediaColumns.DATA};        Cursor cursor=getContentResolver().query(contentUri, proj, null, null, null);        if(cursor.moveToNext()){            return cursor.getString(cursor.getColumnIndex(MediaStore.MediaColumns.DATA));        }        cursor.close();        return null;    }}

  

 

转载于:https://www.cnblogs.com/woaijingjing/p/11127590.html

你可能感兴趣的文章
【bzoj5016】[Snoi2017]一个简单的询问 莫队算法
查看>>
Ajax : load()
查看>>
MySQL-EXPLAIN执行计划Extra解释
查看>>
Zookeeper概述
查看>>
Zookeeper一致性级别
查看>>
Linux远程登录
查看>>
Linux自己安装redis扩展
查看>>
HDU 1016 Prime Ring Problem(dfs)
查看>>
C#中结构体与字节流互相转换
查看>>
session和xsrf
查看>>
跟随大神实现简单的Vue框架
查看>>
Linux目录结构
查看>>
LeetCode-Strobogrammatic Number
查看>>
luoguP3414 SAC#1 - 组合数
查看>>
五一 DAY 4
查看>>
(转)接口测试用例设计(详细干货)
查看>>
【译】SSH隧道:本地和远程端口转发
查看>>
win8.1安装Python提示缺失api-ms-win-crt-runtime-l1-1-0.dll问题
查看>>
图片点击轮播(三)-----2017-04-05
查看>>
判断两个字符串是否相等【JAVA】
查看>>