2

Few weeks ago I decided to make an app, this app contained just video links that allows the users to watch clips whenever they click any button link.

I am using this code to play video:

Intent intent = new Intent(Intent.ACTION_VIEW); 
intent.setDataAndType(Uri.parse("http://www.yourvideo.mp4"), "video/mp4"); 
view.getContext().startActivity(intent); 

However, in some cases this code doesn't work in several devices, some users of my app said it force closes the entire app whenever they press any link. I actually tried it in my G1 and Droid X, it worked perfectly fine.

Is there anything I am doing wrong? Please help me, I would really appreciate it a lot.

Maveňツ
  • 1
  • 12
  • 50
  • 89
user739375
  • 219
  • 3
  • 4
  • 13

2 Answers2

6

First, the video may have issues, as not all videos are safe for streaming.

Second, not all devices may have activities set up to support ACTION_VIEW on video/mp4 files that are streamed. You should use PackageManager and queryIntentActivities() to confirm whether the startActivity() call will find a match, or handle the ActivityNotFoundException that you get.

Community
  • 1
  • 1
CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
3

I wrote this :

Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.parse("http://www.yourvideo.mp4"), "video/mp4");

Then i add the permission : android.permission.WRITE_EXTERNAL_STORAGE , to my manifest.

Taryn
  • 242,637
  • 56
  • 362
  • 405
Kowlown
  • 920
  • 10
  • 26