i m trying to create a videoplayer that getting videos from a path in the sdcard.unfortunately i m getting a nullpointer!Could you please help me?? this is the code:
class VideoFilter implements FilenameFilter {
public boolean accept(File dir, String name) {
return (name.endsWith(".wmv"));
}
}
public class video extends ListActivity {
private static final String MEDIA_PATH = new String("/sdcard/videodata/");
private List<String> songs = new ArrayList<String>();
ArrayAdapter<String> videoList ;
File home = new File(MEDIA_PATH);
private VideoView mVideoView;
@Override
public void onCreate(Bundle icicle) {
try {
super.onCreate(icicle);
setContentView(R.layout.main3);
updateVideoList();
} catch (NullPointerException e) {
Log.v(getString(R.string.app_name), e.getMessage());
}
}
private void updateVideoList() {
// TODO Auto-generated method stub
if (home.listFiles( new VideoFilter()).length > 0) {
for (File file : home.listFiles( new VideoFilter())) {
songs.add(file.getName());
}
videoList开发者_开发知识库 = new ArrayAdapter<String>(this,R.layout.video_item,songs);
setListAdapter(videoList);
}
}
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
mVideoView.setVideoPath(MEDIA_PATH + songs.get(position));
mVideoView.setMediaController(new MediaController(this));
mVideoView.requestFocus();
}
}
@martin if i do it like that
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
setContentView(R.layout.main2);
mVideoView = (VideoView) findViewById(R.id.VideoView);
mVideoView.setVideoPath(MEDIA_PATH + songs.get(position));
mVideoView.setMediaController(new MediaController(this));
mVideoView.requestFocus();
}
then i m getting 07-03 15:55:55.190: ERROR/AndroidRuntime(4090): java.lang.RuntimeException: Your content must have a ListView whose id attribute is 'android.R.id.list'
EDIT:
public class mainscreen extends Activity {
Bundle extras = getIntent().getExtras();
final int VIDEOS = extras.getInt("VIDEO");
private VideoView mVideoView;
String k= new Integer(VIDEOS).toString();
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main2);
mVideoView = (VideoView) findViewById(R.id.VideoView);
mVideoView = (VideoView) findViewById(R.id.video);
mVideoView.setVideoPath(k);
mVideoView.setMediaController(new MediaController(this));
mVideoView.requestFocus();
}
thats the way i m passing the path string from the first activity t the second but its not working.............
You need to fetch your videoview first:
mVideoView = (VideoView) findViewById(R.id.myvideoview);
Edit
Your content must have a ListView whose id attribute is 'android.R.id.list'. It's as simple as that. In your main2.xml you need a ListView with the id 'list'.
Edit2
So you want to get rid of your ListView as you play the video. I'd recommend indeed starting a new Activity for this. ListActivity doesn't allow contents without a ListView.
精彩评论