VideoBrowserActivity.java revision 6cb8bc92e0ca524a76a6fa3f6814b43ea9a3b30d
1/* 2 * Copyright (C) 2007 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17package com.android.music; 18 19import android.app.ListActivity; 20import android.content.ContentResolver; 21import android.content.ContentUris; 22import android.content.Intent; 23import android.database.Cursor; 24import android.media.AudioManager; 25import android.os.Bundle; 26import android.provider.MediaStore; 27import android.view.View; 28import android.widget.ListView; 29import android.widget.SimpleCursorAdapter; 30 31import java.lang.Integer; 32 33public class VideoBrowserActivity extends ListActivity implements MusicUtils.Defs 34{ 35 public VideoBrowserActivity() 36 { 37 } 38 39 /** Called when the activity is first created. */ 40 @Override 41 public void onCreate(Bundle icicle) 42 { 43 super.onCreate(icicle); 44 setVolumeControlStream(AudioManager.STREAM_MUSIC); 45 init(); 46 } 47 48 public void init() { 49 50 // Set the layout for this activity. You can find it 51 // in assets/res/any/layout/media_picker_activity.xml 52 setContentView(R.layout.media_picker_activity); 53 54 mTrackList = (ListView) findViewById(android.R.id.list); 55 56 MakeCursor(); 57 58 if (mCursor == null) { 59 MusicUtils.displayDatabaseError(this); 60 return; 61 } 62 63 if (mCursor.getCount() > 0) { 64 setTitle(R.string.videos_title); 65 } else { 66 setTitle(R.string.no_videos_title); 67 } 68 69 // Map Cursor columns to views defined in media_list_item.xml 70 SimpleCursorAdapter adapter = new SimpleCursorAdapter( 71 this, 72 android.R.layout.simple_list_item_1, 73 mCursor, 74 new String[] { MediaStore.Video.Media.TITLE}, 75 new int[] { android.R.id.text1 }); 76 77 setListAdapter(adapter); 78 } 79 80 @Override 81 protected void onListItemClick(ListView l, View v, int position, long id) 82 { 83 Intent intent = new Intent(Intent.ACTION_VIEW); 84 mCursor.moveToPosition(position); 85 String type = mCursor.getString(mCursor.getColumnIndex(MediaStore.Video.Media.MIME_TYPE)); 86 intent.setDataAndType(ContentUris.withAppendedId(MediaStore.Video.Media.EXTERNAL_CONTENT_URI, id), type); 87 88 startActivity(intent); 89 } 90 91 private void MakeCursor() { 92 String[] cols = new String[] { 93 MediaStore.Video.Media._ID, 94 MediaStore.Video.Media.TITLE, 95 MediaStore.Video.Media.DATA, 96 MediaStore.Video.Media.MIME_TYPE, 97 MediaStore.Video.Media.ARTIST 98 }; 99 ContentResolver resolver = getContentResolver(); 100 if (resolver == null) { 101 System.out.println("resolver = null"); 102 } else { 103 mSortOrder = MediaStore.Video.Media.TITLE + " COLLATE UNICODE"; 104 mWhereClause = MediaStore.Video.Media.TITLE + " != ''"; 105 mCursor = resolver.query(MediaStore.Video.Media.EXTERNAL_CONTENT_URI, 106 cols, mWhereClause , null, mSortOrder); 107 } 108 } 109 110 private ListView mTrackList; 111 private Cursor mCursor; 112 private String mWhereClause; 113 private String mSortOrder; 114} 115 116