I'm using the following code in an application of mine, and it's always used to work with the default video player in Android 3.0 - 3.2. I haven't updated the OS, but for some reason the default video player no longer shows up as an option when you select which application you want to open the video file with.
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.parse(filePath), "video/*");
startActivity(intent);
I may have changed the setDataAndType() method from Uri.fromFile(file) to Uri.parse(filepath), but would that be enough to make such a difference?
Any ideas?
Try using a real MIME type, for the actual type of the video, rather than one with a wildcard.
I've finally found a solution to my question, and I think it's rather weird. The following bit of code does not work:
myIntent.setDataAndType(Uri.parse(filePath), "video/*");
... but this does:
myIntent.setDataAndType(Uri.fromFile(new File(filePath)), "video/*");
It would appear that Uri.fromFile() is required if you want the default OS video player to pop up in the list of applications capable of opening the video file. I have no idea why that's the case though.
Related
I have an application which needs to ask the user for a file. I achieve it by starting an activity using an intent with Intent.ACTION_GET_CONTENT action and "file/*" MIME type.
It works fine on earlier android versions than 4.4. System shows the list of installed file managers, and my app gets a "file://" URL after I choose a file.
The problem comes when I run the app on KitKat. When the app wants to open a file on KitKat, the new built-in file picker shows up. It lists various sources to open a file, such as "Downloads", etc. But all files are greyed out. I can't open them. Ok, when I change MIME type to "*/*", it lets me open the same files. Then I open a file, and my application receives a "content://" style URL as result.
I know how to read data from those URLs, but it would be hard to rewrite the whole app to support it. It's a large one and was intended to work with files.
Is there any way to strictly define in the Intent that I want a "file://" url?
Or is there a way to prevent KitKat from using the new file picker framework? Is there any way to have it working in the same way as on earlier versions?
Can this problem be solved without implementing "content://"-style URL support in the app? Probably it would be the clearest solution...
Thanks in advance!
I have a problem with playing video in my app. Basically what I want to do is getting direct link to video like: www.embed.videotube.com/player/?id=431436[...].mp4 from: http://embed.videotube.com/player/?id=431436. I've seen some websites like www.videotools.12pings.net which will get proper link.
Is there any option how to cope in situation where there is no proper API ? (example: api for youtube)
After clicking on video thumb:
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("www.embed.videotube.com/player/?id=431436[...].mp4"));
myContext.startActivity(intent);
That seems to be a direct link. You could verify it by running fiddler or any HTTP traffic monitoring tool, while playing the video, the video link will be displayed in the inspector window.
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 am using the following code to play youtube videos in my app.
startActivity(new Intent(Intent.ACTION_VIEW,
Uri.parse("http://www.youtube.com/watch?v=videoid")));
I would like the youtube videos to open in full screen mode. Is there any way to achieve this?
Found this solution today:
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.youtube.com/watch?v=VIDEOID"));
intent.putExtra("force_fullscreen",true);
startActivity(intent);
Try using
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("vnd.youtube://" + video_id);
startActivity(intent);
The reason is the different Uri. The one you are currently using is just supplying content via http: that happens to be video and get's resolved to youtube. The one with "vnd.youtube" is actually telling the system that you have video content you would like one of the native apps to take care of.
Ahh, if you want to actually play full screen video without using the youtube app (which you can not control) you don't you try to just make your own VideoView?
Check out this link
playback video full screen
Although I failed at this initially, I eventually succeeded by following the instructions at this linkc
http://keyeslabs.com/joomla/projects/youtube-player/244-open-youtube-activity-project-launched-by-keyes-labs
Here you create your own video player and the video gets played in it
To capture video in an Android app, I'm using the MediaStore.ACTION_VIDEO_CAPTURE action, with EXTRA_OUTPUT to specify the location of the new video file. But how do I know what the MIME type is? Right now I just assume that it's “video/mp4”, but is there a way to get the video capture activity to tell me what the type is?
Well, the file type that pops up on SD cards is 3gp. Not sure about the encoding.
As best I can tell, the EXTRA_OUTPUT is a copy of the video that doesn't replace the one saved in the standard location. So if you're just worried about having the correct extension, it doesn't really matter...