1

I try to play a video from SD card.Thats why i try this code

public class VideoPlayActivity extends Activity {
private VideoView video;
private MediaController ctlr;

@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
getWindow().setFormat(PixelFormat.TRANSLUCENT);
setContentView(R.layout.main);

File clip=new File(Environment.getExternalStorageDirectory(),
                   "haha.mp4");


if (clip.exists()) {
  video=(VideoView)findViewById(R.id.video);
  video.setVideoPath(clip.getAbsolutePath());

  ctlr=new MediaController(this);
  ctlr.setMediaPlayer(video);
  video.setMediaController(ctlr);
  video.requestFocus();
  video.start();
}
}
}

While i run this code in android device the video not display just the black screen.When i disconnect my phone and open this project the video play .What is actual problem inside the code?

ThomasW
  • 16,981
  • 4
  • 79
  • 106
MBMJ
  • 5,323
  • 8
  • 32
  • 51
  • As gtumca said, the SD card isn't mounted. You'll need to turn off the USB drive feature. In your code, you really should be checking for the state of the SD card. Many google results similar: http://stackoverflow.com/questions/902089/how-to-tell-if-the-sdcard-is-mounted-in-android – Phix May 24 '12 at 07:55
  • when you connect your device sdcard will unmounted internally. But disconnect your device sdcard will mounted automatically. So, if your device is connected to PC then your code could not find sdcard. – MAC May 24 '12 at 07:53
  • 1
    This is not all about sd card mounting.I solve the problem.I use `` while previously i used `match_parent` – MBMJ May 24 '12 at 08:50

0 Answers0