I want to get YouTube Videos in Android VideoView for my application.
I am going through the Google's YouTube API. I have generated the Client ID,Client Secret,redirect-URL and code by the help of this API Documentation.
https://developers.google.com/youtube/2.0/developers_guide_protocol#OAuth2_Installed_Applications_Flow
Next step is to get Access Token for Installed Applications, I am doing the same as the above Doc is explaining but getting this error.
java.io.FileNotFoundException: https://accounts.google.com/o/oauth2/token?code=4/sfsekiMy-EWE_7der69fy3wsdfdsseclient_id=412600012302.apps.googleusercontent.com&client_secret=0P7H4yqRZY2jmpluiyswqnbz&redirect_uri=http://localhost/oauth2callback&grant_type=authorization_code
Any help is highly appreciated OR you can suggest some way to access YouTube video in my Android App using only MediaPlayer and VideoView.
Thanks in advance.
Try this thread How to play YouTube video in my Android application?
Steps:
a. Create a new Activity, for your player(fullscreen) screen with menu options. Run the mediaplayer and UI in different threads.
b. For playing media - In general to play audio/video there is mediaplayer api in android. FILE_PATH is the path of file - may be url(youtube) stream or local file path
MediaPlayer mp = new MediaPlayer();
mp.setDataSource(FILE_PATH);
mp.prepare();
mp.start();
Related
So I am creating a podcasting app and I was wondering if playing a podcast such as this http://www.npr.org/rss/podcast.php?id=122287224 - will MediaPlayer work to play such a podcast? I have never used MediaPlayer and I am just wondering if that would work.
yea you can , just parsing the xml and get the link of the xml and using the media player in streaming the mp3
this tutorial help you
here how to parse xml
http://www.androidhive.info/2011/11/android-xml-parsing-tutorial/
media player and streaming
http://www.helloandroid.com/tutorials/musicdroid-audio-player-part-i
http://blog.pocketjourney.com/2008/04/04/tutorial-custom-media-streaming-for-androids-mediaplayer/
http://blog.endpoint.com/2011/03/api-gaps-android-mediaplayer-example.html
http://androidstreamingtut.blogspot.com/2012/08/custom-progressive-audio-streaming-with.html
I'm having trouble playing a certain .3gp file (from a Dropbox link) with Android's MediaPlayer. However the file magically plays without problems from the Dropbox Android app.
I'm trying to play it using this:
Intent intent = new Intent(android.content.Intent.ACTION_VIEW);
intent.setData(Uri.parse("https://www.dropbox.com/s/zpiqwmxka6llavt/SketchyFile.3gp"));
startActivity(intent);
and my manifest contains
<uses-permission android:name="android.permission.INTERNET" />
which gives a "Can't play this video" error.
Logcat shows:
I/NuCachedSource2(89): new range: offset= 2245017
I/ChromiumHTTPDataSource(89): connect to https://dl.dropbox.com/0/view/a1crokuhpprsaeo/SketchyFile.3gp #2245017
I/NuCachedSource2(89): ERROR_END_OF_STREAM
E/MediaPlayer(3629): error (1, -2147483648)
E/MediaPlayer(3629): Error (1,-2147483648)
D/VideoView(3629): Error: 1,-2147483648
If I try to play it from the Dropbox Android app, Dropbox's video player has no problem playing it.
According to ffmpeg's ffprobe tool I could verify that the media type is not something exotic to Android.
Is Dropbox performing some weird transcoding voodoo and is there a way I can make this work in a similar way?
EDIT: Here's some more insight into DropBox's encoding voodoo.
Since I neither have the drop box app source or access to the actual file here is my best case guess that I will make on basis of a couple of assumptions.
The file is not playable by the native app because it is in a format that cannot be played there. Can you say download the file, put it in a sd card and then play it? If not, then the phone does not support this format.
Why does dropbox player play it? My guess based on same assumption is that drop box player adds its own decoding library (eg. ffmpeg ) along with it below the jni. So it can decode this.
Another possible guess:
You are trying to do a streaming play of 3gp file which is not possible.HTTP pd play may be possible. Again, download it and play it from sd card, if it plays, then probably this is the issue.
This file may not be hinted which it needs to be.
Drop box is playing this because perhaps the dropbox app is somehow accessing the header which is at end of file (your voodoo) through some other api?
Again both of the above are guesses from common problems i see as I neither have the dropbox app source, access to your file or know exactly how you are trying to play the video using native player.Perhaps one of the above tips help. Good luck!
EDIT: Issue seen: Nexus S does not play given file locally or from http link. Turns out remuxing to mp4 made Nexus S play it both ways. This implies 3gp support is not there in local native player in some android devices.
You can Use try-catch like follows :
try
{
VideoView videoView = (VideoView) findViewById(R.id.VideoView);
MediaController mediaController = new MediaController(this);
mediaController.setAnchorView(videoView);
// Set Audio/Video
String strfilename = "http://example.com/video.mp4";
Uri video = Uri.parse(strfilename);
videoView.setMediaController(mediaController);
videoView.setVideoURI(video);
videoView.start();
}
catch (Exception e)
{
//enter code here
//Handle Errors
}
I have rtsp audio streams from a specific site (m.aveamuzik.com) that play within a browser. When I try to play the same stream using MediaPlayer class, I get MEDIA_ERROR_UNKNOWN (with extra=-2147483648). The error is not well documented but a little googling shows that it is most probably because of unsupported media format.
My question is, if MediaPlayer class does not support some format, how does the built-in browser play it? Also, how to use the same mechanism used by the browser in my code, instead of the MediaPlayer class?
Edit 1: #Joe
I tried the following code:
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(streamURL));
startActivity(intent);
MX Player and BSPlayer showed up as options to open the file, but not anything related with AudioPreviewActivity. Actually this is quite reasonable as my URLs are rtsp, but the intent filters for AudioPreviewActivity are just for http, file and content type of URIs.
Fact
The Browser has extra features set up to strip the video source from the page and launch it in the native player most of the time. This functionality is not built into WebView, and the native player is very picky about what needs to passed into it as a URI to be able to play it.
It works since Gingerbread in the default android browser.
Possible explaination
You probably don't use the MediaPlayer the way the android browser does. Post some code to help futher help.
Further help
The MediaPlayer has a lot of bugs before 4.0 (that fixed a lot a RTSP bugs).
The Web Audio API as described by W3C: link
Here is a detailed list of all media formats and protocols supported by Android: link
Testing page: link
This complete blog post also helped me about media streaming for Android: link
If it looked like the screenshot on this other question when it is playing in the Browser, then it should be the AudioPreview Activity from the Music app.
You should be able to
launch it by simply calling startActivity() with an Intent that matched one of its IntentFilter in the manifest.
I want to play a remote video in a Videoview. Anybody knows a good free server to load my videos in it to later stream in a videoview? Is possible to see in a videoview Youtube videos? I have see another questions but I donĀ“t understand. Anybody can put a example to play a Youtube video or remote video for another server in a videoview?
Thank you
You can check android-youtube-player, a project to make YouTube videos play in a VideoView. The usage instructions and sample Activity code is available.
You can definitely stream video directly into a VideoView without a problem, and you set it up normally as well:
Uri pathtoVideo = Uri.parse(path);
videoView.setVideoURI(pathToVideo);
However, there are a lot of videos on Youtube that aren't mobile-friendly, and will end up throwing a "This Video Cannot Be Played" error.
The MediaPlayer on Android can only play "progressive streamable contents" which basically means: 1. the movie atom has to precede all the media data atoms. 2. The clip has to be reasonably interleaved. If it doesn't, you'll get the error I mentioned above.
Have you considered the YouTube API for android? I recently posted a tutorial on how to use the video and thumbnail views from the API here
Please provide some url related to some documentation about video streaming in android. I got many document on this site but all are getting total content of video from url and then playing the video but i want to stream and play video simultaneously so that i can play without consuming a lot of time. thank you
There are two techniques:
Using MediaPlayer: If you are using streaming server to fetch video then just provide your URL in MediaPlayer source. MediaPlayer will manage everything.
Manually: If you are not using streaming server for video then you need to download and play video. Use following link as example. In following link author explain audio streaming. You can use same technique for video.
http://blog.pocketjourney.com/2008/04/04/tutorial-custom-media-streaming-for-androids-mediaplayer/