VideoVIew from resource - android

Dear All;
I am new in android app;
I try to play video from my resource , but no idea how to do it...
any help??
regards..

I think the following can help (that's the way I implement it):
VideoView vd;
vd = (VideoView) findViewById(R.id.VideoView);
Uri uri = Uri.parse("android.resource://org.android.Test.Test/raw/vid"); vd.setVideoURI(uri);
vd.start();
where Test.Test is the name of my package.
Remark: You didn't ask it, but some video files do not work on emulator (you hear only
the music, but see no picture). In this case debug it on your phone.

Related

How to display mp4 video in videoview from raw folder

I am trying to display a mp4 video from a raw folder. The video is supposed to play in a videoview automatically when the app is open. I want the video to begin as soon as the activity is launched (This is the launcher activity). I also want the video to loop and have no sound. My xml is below.
<VideoView
android:id="#+id/launcherVideo"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="#+id/linearLayout" />
This is the code I have.
String fileName = "android.resource://"+ getPackageName()+"/raw/launchervideo";
VideoView mvideo = (VideoView) findViewById(R.id.launcherVideo);
mvideo.setVideoPath(Launcher);
MediaController controller = new MediaController(this);
mvideo.setMediaController(controller);
mvideo.requestFocus();
mvideo.start();
}
This code currently does not do anything but display a blank screen when I run the app and I don't know why. Can anyone help out?
I don't see you use this variable, and I don't see how you define Launcher variable.
String fileName = "android.resource://"+ getPackageName()+"/raw/launchervideo";
to open video file from raw folder you can do this way:
Uri uri = Uri.parse(fileName);
mvideo.setVideoURI(uri);
mvideo.start()
I hope it can help solve your problem
Thanks for the help guys, I figured it out.
VideoView videoView = (VideoView) findViewById(R.id.launcherVideo);
Uri src = Uri.parse("android.resource://com.package/raw/video_name");
videoView.setVideoURI(src);
//videoView.setMediaController(new MediaController(this));
videoView.start();
This worked for me.

Video not playing

I am using VideoView trying to play video. But when I use this code I have following error:
Sorry, this video cannot be played
What is wrong here?
VideoView vv = (VideoView) findViewById(R.id.videoView);
String path = "/mnt/sdcard/Video/1345467237098.m4v"
vv.setVideoPath(path);
This format is not supported, please check this url https://developer.android.com/guide/topics/media/media-formats.html
Th format in which the video is, is not supported by Android. I suggest you convert your video to .mp4 (which is supported).
I hope this helps.

Loading a video (mp4) file in android

VideoView v = (VideoView) findViewById(R.id.VideoView01);
Uri uri = Uri.parse("android.resource://" + getPackageName() + "vid.mp4");
mc = new MediaController(this);
v.setMediaController(mc);
v.setVideoURI(uri);
v.start();
An alertbox appears saying that the video cannot be played.Do you have a solution to this .
thanks in advance
This is a linux filesystem permission issue. The location of the file is solely owned by your application. The MediaPlayer service ViewView relies on runs as a different "user" from a file system perspective.
The way I've solved this in the past is to create a custom VideoView extending SurfaceView that takes a FileDiscriptor as it's data source.
This side steps the issue by providing a connection to the data the is already open as far as the file system is concerned.
If your feeling frisky you could pull down the VideoView code from google and add a new setVideoFileDiscriptor method.

Android SDK - Media Player Video from URL

I've tried to find a simple tutorial which explains how to load a video from a URL into the android media player but unfortunately I couldn't find any!
I have tried several things to try get it working but still no luck.
What is the best way to have a MediaPlayerActivity just load a video from a URL?
Thanks
EDIT:
I have tried the following code as suggested:
VideoView videoView = (VideoView) findViewById(R.id.your_video_view);
MediaController mediaController = new MediaController(this);
mediaController.setAnchorView(videoView);
videoView.setMediaController(mediaController);
videoView.setVideoURI(Uri.parse("url-here"));
videoView.start();
It just crashes when I go to this activity.
You can use a VideoView. Here is an example:
VideoView videoView = (VideoView) findViewById(R.id.videoView);
//Use a media controller so that you can scroll the video contents
//and also to pause, start the video.
MediaController mediaController = new MediaController(this);
mediaController.setAnchorView(videoView);
videoView.setMediaController(mediaController);
videoView.setVideoURI(Uri.parse(videoUrl));
videoView.start();
EDIT
You should provide the URI (having a String url variable, where it has the url of the video) with this code Uri.parse(url). And also be sure if the url is appropriate. Also, have you provided the appropriate permissions to your app, as AkashG suggested, (since it uses the internet you will need to add <uses-permission android:name="android.permission.INTERNET" > in your app's Manifest.xml)? Finally you should define your activity MediaPlayerActivity in in your app's Manifest.xml
End of EDIT
You can also use MediaPlayer. The Android developers site has a good tutorial here.
you can load video from url as:
VideoView videoView = (VideoView) findViewById(R.id.view);
MediaController controller = new MediaController(this);
videoView.setVideoPath("url of the video");
videoView.setMediaController(controller);
videoView.start();
Add internet permission in manifest file.
I think you can find useful thinks Here.. about playing video from different sources.
If your using Emulator ,
First, do not use the emulator for testing video playback. Its ability to handle video playback is very limited. Use an actual Android device.
Second, always check LogCat (adb logcat, DDMS, or DDMS perspective in Eclipse) for warnings when you run into multimedia problems. OpenCORE -- the multimedia engine used by Android -- has a tendency to log error-level conditions as warnings.
For example, your video file may not be set up for progressive download, which is required for HTTP streaming. On Linux, you can patch up MP4 videos for progressive download by installing MP4Box and running MP4Box -hint .
Hope this explanation works for you..

How to play videos from SD Card

I was creating a simple app which stream videos from net and I made it but now I want to change the code so that I can play video files from my SDCard
original code:
Uri vidFile = Uri.parse("MY SITE HERE");
VideoView videoView = (VideoView) findViewById(R.id.VideoView);
videoView.setVideoURI(vidFile);
videoView.setMediaController(new MediaController(this));
videoView.start();
So please help me with changing the code so that it can play videos from my mobile memory card.
The videoView.setVideoURI(vidFile); method needs to be replaced by the videoView.setVideoPath(path); method.
Here path specifies the path of the video file on the SDCARD.
This path can be easily retrieved using the MediaStore.Video.Media.DATA property of that video file or by just entering the songpath statically as /sdcard/songname.
Uri vidFile = Uri.parse(
Environment.getExternalStorageDirectory().getAbsolutePath()+"filename");
...
the rest of the code will be same.
In place of
videoView.setVideoUri(vidFile)
use
videoView.setVideoPath("/sdcard/SONG.").
Let me know.
these links may help you:
Playing 3gp video in SD card of Android
how-play-video-and-audio-android
Using VideoView to play mp4 from sdcard
I also tried your code and got same error message but when I tried with video path with no blank space in path or name, it worked well. Just give it a try.
e.g,
file path "/mnt/sdcard/Movies/Long Drive Song - Khiladi 786 ft. Akshay Kumar_Asin-YouTube.mp4"
gave the error but file path "/mnt/sdcard/Movies/Khiladi.mp4" worked well.
I know is is old but if it can help. add this to your manifest
<uses-permission android:name="com.android.externalstorage.ExternalStorageProvider"/>

Categories

Resources