I want to open video file and set the previewed title in video player with a different title than the file name (which is used by default).
String videoFile = "Video file url / path";
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.parse(videoFile), "video/mp4");
// Is there an extra to set the previewed video title?
mMainActivity.startActivity(intent);
There is no documented extra for ACTION_VIEW that would offer this, and third-party video players would not have to honor it anyway. You are welcome to implement your own video player in your own app if you wish to control the title.
Related
I want to share a video to instagram from my app, using my app logo as a sticker. I have been following this documentation, but the results is that everytime I try to share, instagram opens, shows me my video and the sticker, it freezes for about a second, and then the sticker dissapears, only leaving me with my video and no sticker to be seen, even after posting said video.
I have also read this question, where they stated that not being able to share a sticker with a video was a bug with android, but it should now be fixed. The image Im using for the sticker is 640x480 which is the recommended size according to documentation so I dont think is the image size either. I can only think Im sharing it wrong.
Here is my code:
Uri stickerAssetUri = Uri.parse("android.resource://" + R.class.getPackage().getName() + "/drawable/" + R.drawable.app_logo_sticker);
File media = new File(localFilePath);
Uri backgroundAssetUri = FileProvider.getUriForFile(getActivity(), getString(R.string.file_provider), media);
Intent intent = new Intent("com.instagram.share.ADD_TO_STORY");
intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
intent.setDataAndType(backgroundAssetUri, "video/mp4");
intent.putExtra("interactive_asset_uri", stickerAssetUri);
getActivity().grantUriPermission(
"com.instagram.android", stickerAssetUri, Intent.FLAG_GRANT_READ_URI_PERMISSION);
if (getActivity().getPackageManager().resolveActivity(intent, 0) != null) {
getActivity().startActivityForResult(intent, 0);
}
The problem was the video file I was using for testing. The max duration for a background asset is 20 seconds, and while the file I was using was 20 seconds according the videoview, retrieving the actual duration of the video gave me 20333 milis which is over the limit specified in the documentation. I used a different file that actually meets the criteria and it works.
I am using this snippet to open a video using default Android Video Player:
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.parse("http://my.video/link.mp4"), "video/mp4");
startActivity(intent);
Now I want to display subtitle on the video, my subtitle is provided with a url, example http://my.subtitle/link.srt. I think there would be something simple like this:
intent.putExtra("subtitle", "http://my.subtitle/link.srt");
But it doesn't seem to be simple like that.
Could anyone show me how to do it? Thanks a lot.
I have app where I have url of media file.
I wish if I could start Music and Video app and play file.
Is there any chance to do that.
I dont want to write my own media player app.
Create an ACTION_VIEW intent with the path to your media file and include the type of media you want to play.
String audioPath = "path/to/audio.mp3";
Intent intent = new Intent();
intent.setAction(android.content.Intent.ACTION_VIEW);
// set the data and type, for movies this would be video/*
intent.setDataAndType(Uri.parse(audioPath), "audio/*");
getContext().startActivity(intent);
You don't have to set the type, but I would suggest doing so. Setting the type will limit the activities to activities that know how to handle the given type.
I call the default audio player using intent. Its playing correctly, but want to hide details of playing URL is display in top of the play.its my coding
String extension = MimeTypeMap.getFileExtensionFromUrl(url);
String mimeType = MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension);
Intent mediaIntent = new Intent(Intent.ACTION_VIEW);
mediaIntent.setDataAndType(Uri.parse(url), mimeType);
startActivity(mediaIntent);
This can't be achieved with with such an implicit intent like that. This is because you have no control over the UI that is being used to play the content. In order to solve your problem, You must play the file using a specific class available in the framework.
I have an application that plays video files.
I have been using code for using Videoview and starting the Videoview manually to play video files. However, I just wanted to know if I can use the default media player or video player of android rather than creating or using the VideoView to play the file..
Please make comments if the question is not clear.
Thanks alot
Sure - just use an Intent with the file Uri.
File file = new File("fileUri");
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(file), "video/*");
startActivity(intent);