I am developing video player app. I want this app to be appear as option on selecting video from sdcard, album or any folder of the phone . When i select my video player to play video, it takes to app but video is not playing. I have given permission to read and write external storage in manifest.Below is my code :
Intent in =getIntent();
file_path = in.getData().getPath();
System.out.println("file path from sdcard:"+file_path);
videoView =(VideoView)findViewById(R.id.video);
MediaController mediaController= new MediaController(this);
mediaController.setAnchorView(videoView);
Uri uri=Uri.parse(file_path);
videoView.setVideoURI(uri);
videoView.requestFocus();
videoView.start();
ERROR :
10-19 10:39:40.917: I/System.out(20430): file path from sdcard:/external/video/media/24363
10-19 10:39:40.987: E/MediaPlayer(20430): Uri is <URL suppressed>
10-19 10:39:40.997: E/MediaPlayer(20430): error (1, -2147483648)
10-19 10:39:41.017: E/MediaPlayer(20430): Error (1,-2147483648)
10-19 10:39:41.017: D/VideoView(20430): Error: 1,-2147483648
EDIT: testing phone : Android 4.1 with 32Gb inbuilt memory and does not have Sdcard.
Answer for this is here
public String getRealPathFromURI(Uri contentUri) {
String[] proj = { MediaStore.Video.Media.DATA };
Cursor cursor = managedQuery(contentUri, proj, null, null, null);
int column_index = cursor.getColumnIndexOrThrow(MediaStore.Video.Media.DATA);
cursor.moveToFirst();
return cursor.getString(column_index);
}
I had this same problem, went down many different paths to fix it, and what finally ended up working was the following code block:
/* inside onCreate */
VideoView videoView = (VideoView)findViewById(R.id.loginVideoBackground);
videoView.setVideoURI(Uri.parse("android.resource://" + this.getPackageName() + "/raw/lights"));
videoView.start();
I had previously tried:
Extending SurfaceView
using the answer given by #brinda above (which was resulting in a NullPointerException)
and various other permutations of StackOverflow answers
....sometimes simpler is better
/external/video/media/24363 is not correct, please check. local path must be visit..e.g. /sdcard/video/media/..
videoView.setVideoPath("http://www.ebookfrenzy.com/android_book/movie.mp4"); MediaController mediaController = new MediaController(this);
mediaController.setAnchorView(videoView);
videoView.setMediaController(mediaController);
videoView.start();
To be honest, I've experienced similar problems in the past and for each account, what I've ultimately found to be the best solution was to extend SurfaceView, directly. There is a surprisingly small amount of code to write and can easily (relatively speaking) be tailored efficiently to your requirements.
Related
Please find below xml
<VideoView
android:id="#+id/video_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
Java Code:
String url = "android.resource://com.example.androidtutorial/" + R.raw.instructions;
videoView.setVideoURI(Uri.parse(url));
videoView.start();
Error is shown in Logcat:
2019-10-20 10:51:16.708 5063-5063/? E/androidtutoria: Unknown bits set in runtime_flags: 0x8000
2019-10-20 10:51:22.825 5063-5080/com.example.androidtutorial E/MediaPlayerNative: error (1, -2147483648)
2019-10-20 10:51:23.178 5063-5063/com.example.androidtutorial E/MediaPlayer: Error (1,-2147483648)
I saw many samples on the internet that uses the same code, but in my case, it is not working.
I advice you to user a WebView instead of video view.
that will work better.
But for your answer
1.check your connection
2.check your permissions
3.check Url that you build with Debug
4.put start method in try catch
Now its seems issue in this line:
videoView.setVideoURI(Uri.parse(url));
uri means a file path in your device not a url, check it and try again.
u can update me in comments
Edited:
use this method:
public Uri getRawUri(String filename) {
return Uri.parse(ContentResolver.SCHEME_ANDROID_RESOURCE +
File.pathSeparator + File.separator + getPackageName() + "/raw/" +
filename);
}
next solution: use Uri.fromFile instead of Uri.parse
And
Use this 2 methods:
video.setVideoURI(URI);
video.setMediaController(new MediaController(this));
video.requestFocus();
video.start();
Try this in your onCreate() method:
Uri URI = getRawUri(instructions);
MediaController mediaController = new MediaController(this);
mediaController.setAnchorView(video)
video.setVideoURI(URI);
video.setMediaController(mediaController);
video.requestFocus();
video.start();
I am developing music application. I have been using exoplayer to play music. I have lived a problem and couldn't find any solution. My problem is that ı have downloaded song file from internet. This song name contains "?" mark. I create path for this song file and use its name. After song downloaded successfully. I play with exoplayer. I create path for this song and set to exoplayer but it couldn't be played.
Song path = /storage/emulated/0/mymusic/downloads/How am I?_009.mp3
Uri uri = Uri.parse(path);
MediaSource mediaSource = new ExtractorMediaSource.Factory(dataSourceFactory).createMediaSource(uri, null, null);
exoPlayer.prepare(mediaSource);
I don't want replace "?" with any character.
How can I play?
Anybody help?
Thanks
you might also want to use something like this if youre planning on playing both offline and online music:
MediaSource mediaSource = new ExtractorMediaSource
.Factory(dataSourceFactory)
.createMediaSource(
isOnlinePath(path) ? Uri.parse(path) : Uri.fromFile(new File(path))
, null, null);
exoPlayer.prepare(mediaSource);
boolean isOnlinePath(String path) {
return path != null &&
(path.contains("http") ||
path.contains(".m3u") ||
path.contains(".pls"));
}
So I'm trying to play a basic avi video in android, it seems to run fine on Windows Media Player, VLC, etc. so it doesn't look like it's requiring any complicated codecs. I have a video view in my app and that's it, and I have my video in my resources directory under:
res/raw/my_video.avi
This is the code I'm using to load my video:
setContentView(R.layout.activity_main);
VideoView videoView = (VideoView) findViewById(R.id.videoView1);
Uri video = Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.my_video);
videoView.setVideoURI(video);
videoView.start();
And it does not work. I get a popup saying "Can't play this video" along with a logcat message:
03-10 01:42:12.102: E/(185): Failed to open file 'android.resource://com.securespaces.android.bootstrap/2130968576'. (No such file or directory)
03-10 01:42:12.102: E/MediaPlayer(9737): error (1, -2147483648)
03-10 01:42:12.142: E/MediaPlayer(9737): Error (1,-2147483648)
I'm running this on a Nexus 5 running 4.4.2 stock by the way. I'm following instructions that I found in other stack over flow questions here: How to play videos in android from assets folder or raw folder? with some minor tweaks so that I am using a VideoView that I grab from a layout file.
I'm really stumped as to why this isn't working. I've browsed through a few questions on this subject, but this feels like something that should be a duplicate. I'm running this on a Nexus 5 running 4.4.2 stock by the way.
To clarify the question, I'm wondering what I am doing wrong, or is there an alternative for just playing a simple AVI video?
Write your package name statically and check whether video plays or not.
Try out as below:
VideoView videoView = (VideoView) findViewById(R.id.videoView1);
Uri video = Uri.parse("android.resource://com.securespaces.android.bootstrap/" + R.raw.my_video);
videoView.setVideoURI(video);
videoView.setMediaController(new MediaController(this));
videoView.requestFocus();
Implement this :
public static void getVideoFromRaw(String rawPath) {
try {
// Start the MediaController
MediaController mediacontroller = new MediaController(mContext);
mediacontroller.setAnchorView(mVideoview);
// Get the URL from String VideoURL
Uri mVideo = Uri.parse(rawPath);
mVideoview.setMediaController(mediacontroller);
mVideoview.setVideoURI(mVideo);
} catch (Exception e) {
Log.e("Error", e.getMessage());
e.printStackTrace();
}
mVideoview.requestFocus();
mVideoview.setOnPreparedListener(new OnPreparedListener() {
// Close the progress bar and play the video
public void onPrepared(MediaPlayer mp) {
mVideoview.start();
}
});
mVideoview.setOnCompletionListener(new OnCompletionListener() {
public void onCompletion(MediaPlayer mp) {
}
});
}
Thanks
I'm using this piece of code to try and open a .mp4 video:
VideoView videoView=(VideoView)findViewById(R.id.videoView1);
MediaController mediaController=new MediaController(this);
mediaController.setAnchorView(videoView) ;
videoView.setVideoPath("R.raw.videoname");
videoView.setMediaController(mediaController) ;
videoView.start();
However, whenever I try to run the app, I get a message saying "Can't play this video". I am using a new Nexus 7 tablet if that means anything.
Also, when I try to open the same file that I have stored in with my movies, the video runs perfectly normally when I use Gallery or Video Player to open it.
Any help is much appreciated.
File file = new File(getFilePath());//file path of your video
MimeTypeMap map = MimeTypeMap.getSingleton();
String ext = MimeTypeMap.getFileExtensionFromUrl(file.getName());
String type = map.getMimeTypeFromExtension(ext);
if (type == null)
type = "*/*";
Uri uri = Uri.parse("www.google.com");
Intent type_intent = new Intent(Intent.ACTION_VIEW, uri);
Uri data = Uri.fromFile(file);
type_intent.setDataAndType(data, type);
startActivity(type_intent);
Make sure there will be no space in video name, otherwise it will not
be played by android VideoView.
If not solved then let me know.
Is there any way I can play a video that has been stored in the raw file, without the use of the uri. If not how do i properly set the uri. Let's say i have file named movie and I want to play it with a videoviewer. How would i do this? Also would i have to write the data to the sd card. or can i just play it from the raw.
Why cant I just do
uri uri.parse("android.resources://"+this.getApplicationContext().getPackageName()+movie);
This is what I have it as now if you could can you point out the errors to me so i know and i wont have to have this problem any more
VideoView videoview = (VideoView) findViewById(R.id.videoView1);
videoview.setKeepScreenOn(true);
videoview.setVideoPath("android.raw://com.example.movievp8");
MediaController controller = new MediaController(videoview.getContext());
videoview.setMediaController(controller);
videoview.start();
videoview.requestFocus();
Here is something that works for me:
videoResource = R.raw.some_video;
String uri = String.format("android.resource://%s/%d", context.getPackageName(), videoResource);
animationCanvas = (VideoView) ui.findViewById(R.id.animation_canvas);
animationCanvas.setVisibility(View.VISIBLE);
animationCanvas.setVideoURI(Uri.parse(uri));
animationCanvas.setOnCompletionListener(this);
animationCanvas.setOnPreparedListener(new OnPreparedListener() {
public void onPrepared(MediaPlayer mp) {
animationCanvas.start();
}
});