现在的位置: 首页 > 综合 > 正文

简易视频播放器

2013年03月25日 ⁄ 综合 ⁄ 共 1761字 ⁄ 字号 评论关闭

比较不错的源码:

倒计时的实现方案 - 类似限时抢购商品等
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();
        }

源码下载

 

抱歉!评论已关闭.