Android 滑动改变视频音量和视频缩略图

  /**
   * 滑动 改变音量
   * @param percent
   */
  private void onVolumn(float percent) {
    if(mVolumn == -1){
      mVolumn = mAudioManager.getStreamVolume(AudioManager.STREAM_MUSIC); //获取当前音量
             if(mVolumn < 0){
           mVolumn = 0;
     }    
       //显示
     mOperationBg.setImageResource(R.drawable.video_volumn_bg);
       mOperationVolumnBrightness.setVisibility(View.VISIBLE);
  }   
   int index = (int) (percent * mMaxVolume + mVolumn);   
   if(index > mMaxVolume){
     index = mMaxVolume;
   } else if(index < 0){
     index = 0;
   }   
   mAudioManager.setStreamVolume(AudioManager.STREAM_MUSIC, index, 0);  //设置音量   
   LayoutParams lp = mOperationPercent.getLayoutParams();
   lp.width = findViewById(R.id.operation_full).getLayoutParams().width * index / mMaxVolume;
   mOperationPercent.setLayoutParams(lp);
  }

  /**
   * 滑动 改变亮度
   * @param percent
   */
  private void onBrightness(float percent) {
    if(mBrightness == -1f){
       mBrightness = getWindow().getAttributes().screenBrightness;
       if(mBrightness < 0.01f){
         mBrightness = 0.50f;
        }    
          mOperationBg.setImageResource(R.drawable.video_brightness_bg); //显示
        mOperationVolumnBrightness.setVisibility(View.VISIBLE);
    
     }   
     WindowManager.LayoutParams lpa = getWindow().getAttributes();
     lpa.screenBrightness = mBrightness + percent;
   
     if(lpa.screenBrightness > 1.0f){
       lpa.screenBrightness = 1.0f;
     } else if(lpa.screenBrightness < 0.01f){
       lpa.screenBrightness = 0.01f;
     }
    getWindow().setAttributes(lpa); //改变亮度   
     LayoutParams lp = mOperationPercent.getLayoutParams();
     lp.width = (int) (findViewById(R.id.operation_full).getLayoutParams().width * lpa.screenBrightness);
     mOperationPercent.setLayoutParams(lp);
  }
 private void init() {
   String[] thumbColumns = new String[]{
       MediaStore.Video.Thumbnails.VIDEO_ID,
       MediaStore.Video.Thumbnails.DATA//缩略图路径
  };
  
 String[] MediaColums = new String[]{
   MediaStore.Video.Media._ID,
      MediaStore.Video.Media.TITLE,//视频名称
      MediaStore.Video.Media.DATA,//视频路径
//    MediaStore.Video.Media.DURATION,
//    MediaStore.Video.Media.SIZE
 };
  
  cursor = this.managedQuery(MediaStore.Video.Media.EXTERNAL_CONTENT_URI, MediaColums, null, null, null);  
  videoList = new ArrayList<VideoInfo>();  
  if(cursor.moveToFirst()){
   do{
    VideoInfo info = new VideoInfo();
    //获取视频名称
    info.videoTitle = cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.Video.Media.TITLE));
    //获取视频的路径
    info.videoPath = cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.Video.Media.DATA));
    
    //获取视频缩略图的路径
    
    String selection = MediaStore.Video.Media._ID + "=?";
    
    int id = cursor.getInt(cursor.getColumnIndexOrThrow(MediaStore.Video.Media._ID));
    String[] selectionArgs = new String[]{
      id+""
    };
    
    Cursor thumbCursor = this.managedQuery(MediaStore.Video.Thumbnails.EXTERNAL_CONTENT_URI, thumbColumns, selection, selectionArgs, null);
    
    if(thumbCursor != null){
     //完成获取视频缩略图的路径
     info.thumbPath = cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.Video.Thumbnails.DATA));
//     info.thumbPath = thumbCursor.getString(thumbCursor.getColumnIndexOrThrow(MediaStore.Video.Thumbnails.DATA));
    }
    
    videoList.add(info);
    
   } while(cursor.moveToNext());
  }
  
  VideoAdapter adapter = new VideoAdapter(this, videoList);
  getListView().setAdapter(adapter);
  
 }
 
 static class VideoInfo {
  String thumbPath;//缩略图路径
  String videoTitle;//视频名字
  String videoPath;//视频的路径
 }


  @Override
  public View getView(int position, View convertView, ViewGroup parent) {
   ViewHolder holder = null;
   if(convertView == null){
    holder = new ViewHolder();
    convertView = getLayoutInflater().inflate(R.layout.list_item, null);
    holder.thumbImage = (ImageView) convertView.findViewById(R.id.thumb_image);
    holder.videoTitle = (TextView) convertView.findViewById(R.id.video_title);
    convertView.setTag(holder);
   } else {
    holder = (ViewHolder) convertView.getTag();
   }
   
   //指定视频名字
   holder.videoTitle.setText(videoItems.get(position).videoTitle);
   
   //指定缩略图
   if(videoItems.get(position).thumbPath != null){
    Bitmap bitmap = ThumbnailUtils.createVideoThumbnail(videoItems.get(position).thumbPath, Thumbnails.MINI_KIND);
    Bitmap bitmap1 = ThumbnailUtils.extractThumbnail(bitmap, 200, 200);
    BitmapDrawable db = new BitmapDrawable(bitmap1);
    holder.thumbImage.setImageDrawable(db);
   }
   
    return convertView;
  }
  
  class ViewHolder {
   ImageView thumbImage;
   TextView videoTitle;
  }

main.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >

    <io.vov.vitamio.widget.VideoView
        android:id="@+id/surfaceview"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true" />

    <FrameLayout
        android:id="@+id/operation_volumn_brightness"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:background="#00000000"
        android:padding="0dip"
        android:visibility="invisible" >

        <ImageView
            android:id="@+id/operation_bg"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/video_volumn_bg" />

        <FrameLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center_horizontal|bottom"
            android:paddingBottom="25dip" >

            <ImageView
                android:id="@+id/operation_full"
                android:layout_width="94dip"
                android:layout_height="wrap_content"
                android:layout_gravity="left"
                android:src="@drawable/video_num_bg" />

            <ImageView
                android:id="@+id/operation_percent"
                android:layout_width="0dip"
                android:layout_height="wrap_content"
                android:layout_gravity="left"
                android:scaleType="matrix"
                android:src="@drawable/video_num_front" />
        </FrameLayout>
    </FrameLayout>

</RelativeLayout>


view_list.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >

    <RelativeLayout
        android:id="@+id/list"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_alignParentBottom="true" >

        <ListView
            android:id="@android:id/list"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="10dip" />
    </RelativeLayout>

</RelativeLayout>


view_list.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >

    <ImageView
        android:id="@+id/thumb_image"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="10dip"
        android:background="@drawable/sms" />

    <TextView
        android:id="@+id/video_title"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerVertical="true"
        android:layout_marginLeft="10dip"
        android:layout_toRightOf="@id/thumb_image"
        android:singleLine="true"
        android:textSize="18sp"
        android:textStyle="bold" />

</RelativeLayout>

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。