zoukankan      html  css  js  c++  java
  • 简易视频播放器

    比较不错的源码:

    倒计时的实现方案 - 类似限时抢购商品等
    http://www.eoeandroid.com/thread-231924-1-1.html

    android 仿IPHONE桌面图标抖动
    http://www.eoeandroid.com/thread-231330-1-1.html

    Android中如何使用ViewPager实现类似laucher左右拖动效果
    http://www.eoeandroid.com/thread-231368-1-1.html

    eoe积分商城:

    http://www.eoeandroid.com/plugin.php?id=auction

    -----------------帖子正文-------------------------

    为了熟悉android视频方面的api,结合论坛里的资料,动手写了一个调用系统API的视频播放器,只能播放系统自带能解码的格式,界面比较简单,如下图:

    代码主要有两个部分:

    1.搜索手机中所有视频并显示

      主要通过以下代码实现:

    cursor = getContentResolver().query(MediaStore.Video.Media.EXTERNAL_CONTENT_URI, mediaColumns, null, null, null);  
               
            
               
            if(cursor.moveToFirst()){  
                do{  
                    VideoInfo info = new VideoInfo();  
                       
                    info.filePath = cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.Video.Media.DATA));  
                    info.mimeType = cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.Video.Media.MIME_TYPE));  
                    info.title = cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.Video.Media.TITLE));  
                       
                    Log.d("-name debug-", info.title+"    "+info.filePath);
                     
                    //获取当前Video对应的Id,然后根据该ID获取其Thumb  
                    int id = cursor.getInt(cursor.getColumnIndexOrThrow(MediaStore.Video.Media._ID));  
                    BitmapFactory.Options options = new BitmapFactory.Options();  
                    options.inDither = false;  
                    options.inPreferredConfig = Bitmap.Config.ARGB_8888;  
                    info.b = MediaStore.Video.Thumbnails.getThumbnail(getContentResolver(), id,  Images.Thumbnails.MICRO_KIND, options);                  
                       
                    //然后将其加入到videoList  
                    videoList.add(info);  
                       
                }while(cursor.moveToNext());  
            }  

    2.播放视频

    通过videoview实现

    protected void onCreate(Bundle savedInstanceState) {
            // TODO Auto-generated method stub
            super.onCreate(savedInstanceState);
            setContentView(R.layout.player);
            viv=(VideoView)findViewById(R.id.videoView);
            mController=new MediaController(this);
            viv.setMediaController(mController);
            String videopath=getIntent().getStringExtra("path");
            if (videopath!=null) 
            {
                    viv.setVideoPath(videopath);
            }
            viv.requestFocus();
            viv.start();
            }


    源码下载

  • 相关阅读:
    微信小程序支付
    python中 try、except、finally执行顺序
    磁盘设备在 Linux 下的表示方法
    sanic中间件和监听器
    sed命令详解
    awk命令详解
    gd库
    php中计算二维数组中某一元素之和
    Linux SVN 命令详解
    PHP array 操作函数
  • 原文地址:https://www.cnblogs.com/vus520/p/2788730.html
Copyright © 2011-2022 走看看