Play parse video in android videoview - java

I have stored a video as a file in Parse.com, it's name in Parse is "eventvideo.mp4". I am trying to retrieve this file and play it in a videoview. However, when I run the application I get the dialog message, "Can't play this video. Could someone please help? This is what I have tried..
final ParseFile file = post.getFile();
if (file.getName().toLowerCase().endsWith(".jpg"))
{
holder.event.setParseFile(file);
} else {
holder.event.setVisibility(View.GONE);
holder.videvent.setVisibility(View.VISIBLE);
Uri myUr = Uri.parse(file.toString());
mc.setAnchorView(holder.videvent);
mc.setMediaPlayer(holder.videvent);
holder.videvent.setVideoURI(myUr);
holder.videvent.requestFocus();
holder.videvent.start();
}

Related

Can't play video in videoview android studio?

I know that there is too many solutions were given, but I can't get the exact solution. My problem is that I have picked one video from internal storage device and after picking video then I have converted to String and set the video to videoView but then also it shows that "Can't play this video" in videoView.
can anyone please help me to find out the solution :(
here is my code
File file = new File(Environment.getExternalStorageDirectory().getAbsolutePath()+"/Download/videos.mp4");
Log.d("video",""+file);
if (file.exists()) {
Uri uri = Uri.fromFile(file);
String video = String.valueOf(uri);
Log.d("video",""+uri);
videoView.setMediaController(new MediaController(this));
videoView.setVideoURI(Uri.parse(video));
videoView.requestFocus();
videoView.start();
}else {
Toast.makeText(this, "No video found", Toast.LENGTH_SHORT).show();
}
With scoped storage (required from API 30) you can't access files directly unless you request the MANAGE_EXTERNAL_STORAGE (on Google Play you need to request it to Google).
The new way is to use the file uri. You can try those ways:
Ask the user to select the file.
private final ActivityResultLauncher<String[]> openDoc =
registerForActivityResult(new ActivityResultContracts.OpenDocument(),
new ActivityResultCallback<Uri>() {
#Override
public void onActivityResult(Uri uri) {
// use uri
}
});
Call it with:
// Use the mimetype you want (optional). Like "text/plain"
openDoc.launch(new String[]{"text/plain"});
Read more here
Get the Media file uri with MediaStore
Read more here
You'll also need the READ_EXTERNAL_STORAGE permission if the file was not created by your app.

How to ON or OFF audio recording using MediaRecorder

I'm implement one demo Video and Audio recording using MediaRecorder
Download the demo from hear : Android MediaRecorder Sample
There is one method prepareVideoRecorder() in MainActivity.java. in this method initialization and set Source Audio and video like:
mMediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
mMediaRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
Now i want to audio ON or OFF functionality.
For that i'll tried like this :
if (!AppSetting.getValue(activity, Config.AUDIO, false)) {
mMediaRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
}else {
mMediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
mMediaRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
}
But app is Crash with below error :
java.lang.IllegalStateException
at android.media.MediaRecorder.setAudioEncoder(Native Method)
So how to i solve this error or there is another solution for Audio ON or OFF:
I Got the solution:
If my switch is ON then if part execute(Sound is record). if my switch is OFF then else part execute(Sound do not record).
if (AppSetting.getValue(activity, Config.AUDIO, false)) {
mMediaRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
mMediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
mMediaRecorder.setMaxDuration(duration);
mMediaRecorder.setProfile(profile);
} else {
mMediaRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
mMediaRecorder.setOutputFormat(profile.fileFormat);
mMediaRecorder.setVideoEncoder(profile.videoCodec);
mMediaRecorder.setVideoEncodingBitRate(profile.videoBitRate);
mMediaRecorder.setVideoFrameRate(profile.videoFrameRate);
mMediaRecorder.setVideoSize(profile.videoFrameWidth, profile.videoFrameHeight);
mMediaRecorder.setMaxDuration(duration);
}

Share video from Android raw folder to any app

I am making one app to allow user to share all video from any sharing app. My issue is file attached successfully but the file content is not attaching. below is my full source code. Let me know where I am making a mistake.
private void shareVideo() {
Intent localIntent = new Intent("android.intent.action.SEND");
Uri localUri = Uri.fromFile(new File(CorporateAdaptor.this.rawVideoId + ".mp4"));
String str = MimeTypeMap.getSingleton().getMimeTypeFromExtension(MimeTypeMap.getFileExtensionFromUrl(localUri.toString()));
localIntent.setType(str);
localIntent.setAction("android.intent.action.SEND");
if (str == null) {
str = "*/*";
}
localIntent.setType(str);
localIntent.putExtra("android.intent.extra.STREAM", localUri);
CorporateAdaptor.this.mContext.startActivity(Intent.createChooser(local Intent, "Where you want to share?"));
}
This is my code that was I am using when user click on the share button. It will open a share dialog and when I select the gmail app, the file is attached but it's showing me a toast message "Couldn't find attachment". And when I click on send email file was not sending.

Play Video From URL By Using Vuforia for Android Native?

I want to play a video from URL by using the Vuforia Android Native API.
I have changed the code in the VideoPlayback sample, as shown below:
VideoPlayback.java
Video from Url
mMovieName[STONES] = "..Youtube Video link..";
mMovieName[CHIPS] = "..Youtube Video link..";
mMovieName[celebVM_LOGO] = "..Youtube Video link..";
I removed some code from VideoPlayerHelper.java as shown below:
for Video from Url, in Load method
AssetFileDescriptor afd = mParentActivity.getAssets().openFd(filename);
mMediaPlayer.setDataSource(afd.getFileDescriptor(),
afd.getStartOffset(), afd.getLength());
afd.close();
Added:
mMediaPlayer.setDataSource(filename);
And removing the code
try {
AssetFileDescriptor afd = mParentActivity.getAssets().openFd(filename);
afd.close();
} catch (Exception e) {
Log.d(LOGTAG, "File does not exist");
mCurrentState = MEDIA_STATE.ERROR;
mMediaPlayerLock.unlock();
mSurfaceTextureLock.unlock();
return false;
}
It's not working, can anybody suggest why? Please refer to this link for more information:
https://developer.vuforia.com/forum/android/how-work-video-url-videoplayback
I believe it will only work with links to the actual videos, for example this one.
mMediaPlayer.setDataSource("../video.mp4"); //or any video type

Save Uri as a file android

So in my app it is receiving an image from another application
Intent intent = getIntent();
String action = intent.getAction();
String type = intent.getType();
if (Intent.ACTION_SEND.equals(action) && type != null) {
handleSendImage(intent); // Handle single image being sent
public void handleSendImage(Intent a)
{
Uri pic = (Uri) a.getParcelableExtra(Intent.EXTRA_STREAM);
}
From here I want to save the Uri as an image in my image gallery.
I know how to save a file in the gallery I am just not sure how I get the Uri in the correct format to save it. I know it contains the image because picView.setImageURI(pic); causes the picture to appear in my activity. I just want to be able to save that image into the gallery. Any ideas on how I would do that? I thought that I could convert the ImageView to a bitmap and go from there but that seems really inefficient to me and there has to be a better way to do it. Since I know you can create Uris from Files but can you create a File from a Uri?

Categories