Play Video From URL By Using Vuforia for Android Native? - java

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

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 get streaming bitrate with MediaPlayer?

I'm developing a stream video app in Android with MediaPlayer. The problem is that I need to show the current bitrate, but I haven't found any valid suggestions on how to do get it?
Here is how I'm setting the video url to play:
mediaPlayer = new MediaPlayer();
try {
mediaPlayer.setDataSource(VIDEO_PATH);
mediaPlayer.prepare();
mediaPlayer.init();
} catch (IOException e) {
e.printStackTrace();
}
I don't know if the only way to get that working is using ExoPlayer (which I've read it may be possible)
Any suggestions?
Thanks!
Apparently you cannot do this with MediaPlayer but you can use MediaMetadataRetriever, which is available since API level 10, i.e., quite a while ago.
int getBitRate(String url) {
final MediaMetadataRetriever mmr = new MediaMetadataRetriever();
try {
mmr.setDataSource(url, Collections.EMPTY_MAP);
return Integer.parseInt(mmr.extractMetadata(MediaMetadataRetriever.METADATA_KEY_BITRATE));
} catch (NumberFormatException e) {
return 0;
} finally {
mmr.release();
}
}
The disadvantage this can have is that you will make an extra HTTP request for getting the metadata (only an RTT if you are streaming from an URI; if you are reading from an file descriptor it could be more serious). Hopefully no big deal.

Play parse video in android videoview

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();
}

Android Mp3 live streaming from url

Hello everyone,
I'm trying to play mp3 audio from a url (radio) using media player class. It is running but it took too much time to start. I know this question is already asked on this site. But I need help. If their is no solution for that kindly tell me alternative method . Reference code or tutorial would be a great help.here is my java code.
public void streaming(String url)
{
MediaPlayer mediaPlayer = new MediaPlayer();
try {
Log.i("stream", "connecting data source");
mediaPlayer.setDataSource(url);
Log.i("stream", "preparing");
mediaPlayer.prepare();
Log.i("stream", "prepared");
mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
}
catch(Exception e){
e.printStackTrace();
}
mediaPlayer.start();
Log.i("stream", "Started");
}
}

Check if Android Media Player can play a file

In Android, is there a way to check if a given file is a legitimate file for the media player? This is my current method of testing if a file is playable or not in a media player.
public boolean isPlayable(File file){
try {
Uri uri = Uri.fromFile(file);
player.setAudioStreamType(AudioManager.STREAM_MUSIC);
player.setDataSource(this, uri);
player.reset();
return true;
} catch (Exception e){
Toast.makeText(this, "Invalid File: " + file.getName(), Toast.LENGTH_SHORT).show();
return false;
}
}
I'm using the exception to test, basically if it throws an exception then something is up and we shouldn't play the file. To me, this doesn't seem very clean even though it seems to do the job just fine. Is there a better way I should be looking at this problem? I just want to know if a file is going to throw an exception before I try to plug it into a media player.

Categories