Reputation: 581
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
Upvotes: 4
Views: 11796
Reputation: 399
I applied this and It worked for me
To show a video from a Google Drive URL in your Android app, follow these steps:
Use a Public URL: Make sure your video is publicly accessible. Convert the Google Drive URL to this format:
https://drive.google.com/uc?export=download&id=FILE_ID
Replace FILE_ID
with the actual ID of your video.
File Size Limit: You can play videos that are up to 100 MB using the method above. For larger videos, proceed to the next step.
Google Drive API: If your video is larger than 100 MB, you’ll need to generate an API key from Google Cloud Platform (GCP). Use the following URL to access your video:
https://www.googleapis.com/drive/v3/files/FILE_ID?alt=media&key=API_KEY
Again, replace FILE_ID
and API_KEY
with your specific values.
By following these steps, you should be able to play videos from Google Drive in your Android application!
Upvotes: -1
Reputation: 180
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");
Upvotes: 0
Reputation: 84
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.
Upvotes: 1