4

I want to show video in android application. I have searched on Google and found below code

VideoView videoView = (VideoView) findViewById(R.id.videoView);

String vidAddress = "https://docs.google.com/a/user.co.jp/file/d/something..private cookie/preview";

Uri videoUri = Uri.parse(vidAddress);

MediaController mediaController = new MediaController(this); mediaController.setAnchorView(videoView); videoView.setMediaController(mediaController);

videoView.setVideoURI(videoUri); videoView.start();

I have placed the above code in onCreate method of activity.

When I run application It gives error "Sorry, this video cannot be played."

Log are displayed as below

07-15 13:58:13.110: V/MediaPlayer-JNI(19546): native_setup
07-15 13:58:13.110: V/MediaPlayer(19546): constructor
07-15 13:58:13.125: V/MediaPlayer(19546): setListener
07-15 13:58:13.125: I/MediaPlayer(19546): path is null
07-15 13:58:13.125: D/MediaPlayer(19546): Couldn't open file on client side, trying server side
07-15 13:58:13.140: V/MediaPlayer(19546): setVideoSurfaceTexture
07-15 13:58:13.140: V/MediaPlayer-JNI(19546): setAudioStreamType: 3
07-15 13:58:13.140: V/MediaPlayer(19546): MediaPlayer::setAudioStreamType
07-15 13:58:13.140: V/MediaPlayer(19546): setVideoSurfaceTexture
07-15 13:58:13.140: V/MediaPlayer(19546): prepareAsync
07-15 13:58:16.810: V/MediaPlayer(19546): message received msg=100, ext1=1, ext2=-2147483648
07-15 13:58:16.810: E/MediaPlayer(19546): error (1, -2147483648)
07-15 13:58:16.810: V/MediaPlayer(19546): callback application
07-15 13:58:16.810: V/MediaPlayer(19546): back from callback
07-15 13:58:16.815: E/MediaPlayer(19546): Error (1,-2147483648)
07-15 13:58:16.815: D/VideoView(19546): Error: 1,-2147483648

I am able to see the video on browser.

Uploaded video file type are mpg, mp4 and wmv

Please help if any one have solution.

Thanks

Edit : After some work I came to know that one reason is Android version 4.0.3. Above mentioned code is working for sample url like http://download.itcuties.com/teaser/itcuties-teaser-480.mp4 only in 4.2.2. Videos from Google docs url still not working. What should I do to play it on 4.0.3

compyutech
  • 578
  • 3
  • 8
  • 26
  • try to use [exoplayer](http://developer.android.com/guide/topics/media/exoplayer.html) and play video in exoplayer may be it will work. – bhavesh kaila Jul 15 '14 at 10:41
  • @bhaveshkaila Hello Bhavesh sir, I tried using exoplayer. In client company they are using android 4.0.3. Since exoplayer core classes are not there in 4.0.3 I changed lib to 4.2.2 but when running on 4.0.3 mobile its giving java.lang.verifyerror – compyutech Jul 29 '14 at 06:36
  • @bhaveshkaila Hello Bhavesh Sir, I tried to play some mp4 video using above code on phone having 4.2.2 and its running fine but not playing on 4.0.3 what can be the reason ? According to documents .mp4 is supported in 3.0+ -- Piyush Merja – compyutech Jul 29 '14 at 06:37
  • Follow this [play google drive video using ](http://stackoverflow.com/questions/29596614/android-stream-video-from-google-drive/33625394#33625394) – Soeurng Sar Nov 10 '15 at 08:12
  • This answer seems best in 2019: https://stackoverflow.com/questions/52892844/i-am-trying-to-play-video-from-google-drive-using-shareable-link-in-video-view-b – Duane Dec 25 '19 at 20:46

3 Answers3

1

The url that you parse to Uri is not compatible with VideoView because it just a web url for embed on Iframe in html.Please follow this here for solution.

Community
  • 1
  • 1
0

This seems like a common problem from what I can find. See this and this.

So the problem is likely that your video isn't the right format (Baseline H.264). Try to find a video with this format or convert yours, and you code should work.

Community
  • 1
  • 1
SvenT23
  • 667
  • 6
  • 19
0

you can use web view

String frameVideo = "<html><body>Video From YouTube<br><iframe width=\"420\" 
height=\"315\"  src=\"https://drive.google.com/file/d/VIDEO_ID/preview\" 
    frameborder=\"0\" allowfullscreen></iframe></body></html>";

    WebView myWebView = (WebView) findViewById(R.id.mWebView);

    WebSettings webSettings = myWebView.getSettings();
    webSettings.setJavaScriptEnabled(true);
    myWebView.loadData(frameVideo, "text/html", "utf-8");
Samy Nagy
  • 190
  • 1
  • 6