1.让其他软件能调起自己写的播放器
1.在功能清单文件添加下面的意图
<intent-filter> <action android:name="android.intent.action.VIEW" /> <category android:name="android.intent.category.DEFAULT" /> <category android:name="android.intent.category.BROWSABLE" /> <data android:scheme="rtsp" /> </intent-filter> <intent-filter> <action android:name="android.intent.action.VIEW" /> <category android:name="android.intent.category.DEFAULT" /> <data android:mimeType="video/*" /> <data android:mimeType="application/sdp" /> </intent-filter> <intent-filter> <action android:name="android.intent.action.VIEW" /> <category android:name="android.intent.category.DEFAULT" /> <category android:name="android.intent.category.BROWSABLE" /> <data android:scheme="http" /> <data android:mimeType="video/mp4" /> <data android:mimeType="video/3gp" /> <data android:mimeType="video/3gpp" /> <data android:mimeType="video/3gpp2" /> </intent-filter>
2.文件或者图片浏览器 //1.调起系统所有的播放-隐式意图 Intent intent = new Intent(); intent.setDataAndType(Uri.parse("视频播放地址"),"video/*"); context.startActivity(intent);
3.视频播放器就会被调起并且播放
uri = getIntent().getData();//文件夹,图片浏览器,QQ空间
4.设置播放地址
videoview.setVideoURI(uri);
2.播放网络视频时候支持显示缓存进度
1_支持播放网络视频有缓冲效果
/** * 判断是否是网络资源 * @param uri * @return*/public boolean isNetUri(Uri uri) { boolean result = false; if (uri != null) { if (uri.toString().contains("http")|| uri.toString().contains("RTSP")|| uri.toString().contains("MMS")) { result = true; } else { result = false; } } return result;}
2_播放网络视频时候支持显示缓存进度
//缓存进度的更新if (isNetUri) { //只有网络资源才有缓存效果 int buffer = videoview.getBufferPercentage();//0~100 int totalBuffer = buffer * seekbarVideo.getMax(); int secondaryProgress = totalBuffer / 100; seekbarVideo.setSecondaryProgress(secondaryProgress);} else { //本地视频没有缓冲效果 seekbarVideo.setSecondaryProgress(0);}
3.监听卡并且提示&监听拖动完成
1_监听卡并且提示
<!-- 卡的效果 --><?
代码
在VideoView中定义监听卡方法和监听完成方法
//设置监听卡2.3包括以后的版本才有videoview.setOnInfoListener(new OnInfoListener() { @Override public boolean onInfo(MediaPlayer mp, int what, int extra) { switch (what) { case MediaPlayer.MEDIA_INFO_BUFFERING_START://当卡的时候和拖动卡的时候回调// Toast.makeText(getApplicationContext(), "视频卡了", 1).show(); player_buffer.setVisibility(View.VISIBLE); isBuffing = true; break; case MediaPlayer.MEDIA_INFO_BUFFERING_END://当卡的时候和拖动卡结束的时候回调// Toast.makeText(getApplicationContext(), "视频不卡了", 1).show(); player_buffer.setVisibility(View.GONE); isBuffing = false; break; } return true; }});
2_自定义监听卡
//监听卡if (!isUseSystem) { if(videoview.isPlaying()){ int buffer = currentPosition - precurrentPosition; if (buffer < 500) { //视频卡了 ll_buffer.setVisibility(View.VISIBLE); } else { //视频不卡了 ll_buffer.setVisibility(View.GONE); } }else{ ll_buffer.setVisibility(View.GONE); }}
3_监听拖动完成
//设置拖动完成videoview.setOnSeekCompleteListener(new OnSeekCompleteListener() { @Override public void onSeekComplete(MediaPlayer mp) { if(isBuffing){ // TODO Auto-generated method stub player_buffer.setVisibility(View.GONE); } }
});
百度搜索:android 获取当前网速
http://www.2cto.com/kf/201412/358191.html
/** * 得到当前的网速 *@paramcontext *@return */public String getNetSpeed(Context context) { long nowTotalRxBytes = TrafficStats.getUidRxBytes(context.getApplicationInfo().uid)==TrafficStats.UNSUPPORTED ? 0 :(TrafficStats.getTotalRxBytes()/1024);//转为KB; long nowTimeStamp = System.currentTimeMillis(); longspeed = ((nowTotalRxBytes - lastTotalRxBytes) *1000 / (nowTimeStamp - lastTimeStamp));//毫秒转换 lastTimeStamp = nowTimeStamp; lastTotalRxBytes = nowTotalRxBytes; String speedStr = String.valueOf(speed) + " kb/s"; return speedStr;}
原标题:手机影音8
关键词: