I am trying to open a video in a videoView using an url.
Here are the code i use:
public void playVideo(){
String path= "http://s3.amazonaws.com/yendis_development/uploads/container/content/4fd79353c83b7260e6000003/3.mpg";
String path1="http://commonsware.com/misc/test2.3gp";
Uri uri=Uri.parse(path);
VideoView video=(VideoView)findViewById(R.id.video_view);
video.setVideoURI(uri);
video.start();
}
When i use "path1", my VideoView get the video and play it fine.
but when i use "path", i don't get the video and i got a dialog saying "Sorry, this video cannot be played".
Why the webview worked for the path1 and not for path? You can open path and path1 in the navigator so you can see videos' test.
When path, In my logcat, i got this message (error):
08-11 17:08:47.411: E/MediaPlayer(10064): error (1, -2147483648)
08-11 17:08:47.411: E/MediaPlayer(10064): Error (1,-2147483648)
08-11 17:08:47.411: D/VideoView(10064): Error: 1,-2147483648
Thanks
Related
I'm trying to play a video using a url but it's not working. It always give me error on screen as Can't play this video.
I'm using below snippet:
val uri: Uri = Uri.parse(it.url)
binding.videoView.setVideoURI(uri)
val mediaController = MediaController(activity)
mediaController.setAnchorView(binding.videoView)
mediaController.setMediaPlayer(binding.videoView)
binding.videoView.setMediaController(mediaController)
binding.videoView.setOnPreparedListener { binding.videoView.start() }
Logcat Error:
E/MediaPlayerNative: error (1, -1015)
E/MediaPlayer: Error (1,-1015)
I'm getting the YouTube url mostly. Thanks in advance.
I get a Url from anyone in this format:
http://ak...
There is a video wich plays with flashplayer.
I want to stream this video from a android app and I tried it with videoview and mediacontroller. But it's not working and I don't know what to do anymore.
Can you give me some keywords to solve the problem, so I could search on the internet for it.
try {
String videoUrl= "http://ak;
// Start the MediaController
MediaController mediacontroller = new MediaController(
LiveStreamActivity.this);
mediacontroller.setAnchorView(videoview);
// Get the URL from String VideoURL
Uri video = Uri.parse(videoUrl);
videoview.setMediaController(mediacontroller);
videoview.setVideoURI(video);
startTimer();
} catch (Exception e) {
e.printStackTrace();
}
videoview.requestFocus();
videoview.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
// Close the progress bar and play the video
#Override
public void onPrepared(MediaPlayer mp) {
videoview.start();
checkBuffering();
}
});
This is my code and the logcat is:
I/MediaPlayer: path is null
D/MediaPlayer: setDataSource IOException happend :
java.io.FileNotFoundException: No content provider: http://ak-rt01.mni.thm.de:3000/#/playlist/57b03967e4da719c28d9fe2d
at android.content.ContentResolver.openTypedAssetFileDescriptor(ContentResolver.java:1052)
at android.content.ContentResolver.openAssetFileDescriptor(ContentResolver.java:907)
at android.content.ContentResolver.openAssetFileDescriptor(ContentResolver.java:834)
at android.media.MediaPlayer.setDataSource(MediaPlayer.java:987)
at android.widget.VideoView.openVideo(VideoView.java:337)
at android.widget.VideoView.access$2100(VideoView.java:71)
at android.widget.VideoView$7.surfaceCreated(VideoView.java:617)
at android.view.SurfaceView.updateWindow(SurfaceView.java:601)
at android.view.SurfaceView.access$000(SurfaceView.java:94)
at android.view.SurfaceView$3.onPreDraw(SurfaceView.java:183)
at android.view.ViewTreeObserver.dispatchOnPreDraw(ViewTreeObserver.java:879)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2129)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1234)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6465)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:803)
at android.view.Choreographer.doCallbacks(Choreographer.java:603)
at android.view.Choreographer.doFrame(Choreographer.java:573)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:789)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:157)
at android.app.ActivityThread.main(ActivityThread.java:5356)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1265)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1081)
at dalvik.system.NativeStart.main(Native Method)
D/MediaPlayer: Couldn't open file on client side, trying server side
V/MediaPlayer: setVideoSurfaceTexture
V/MediaPlayer-JNI: setAudioStreamType: 3
V/MediaPlayer: MediaPlayer::setAudioStreamType
V/MediaPlayer: setVideoSurfaceTexture
V/MediaPlayer: prepareAsync
D/ProgressBar: setProgressDrawable drawableHeight = 48
D/AbsSeekBar: AbsSeekBar Constructor: misSeebarAnimationAvailable = true
V/MediaPlayer: message received msg=100, ext1=1, ext2=-1004
E/MediaPlayer: error (1, -1004)
V/MediaPlayer: callback application
V/MediaPlayer: back from callback
E/MediaPlayer: Error (1,-1004)
D/VideoView: Error: 1,-1004
The problem that your media controller is experiencing is that its not able to find a valid video file from the URL. The Video URI for VideoView should be of usually this format http://dummyWebSite/dummy/randomFile.mp4 or http://blah/blah/File.avi . Notice here that the path to the randomFile.mp4 video file uploaded on server is given over here.
For testing purposes, you can use this URL and try the same code by replacing your url with this (valid URL with a mp4 file) http://techslides.com/demos/sample-videos/small.mp4
So what could be some alternatives to this?
ALTERNATIVE 1 (best solution)
Upload your video mp4, mov or avi on a file server and hit the url of your video on the file server.
ALTERNATIVE 2
Open the given link in the android device web browser.
Intent intent = new Intent(Intent.ACTION_VIEW,
Uri.parse("http://ak-rt01.mni.thm.de:3000/#/playlist/57b03967e4da719c28d9fe2d"));
startActivity(intent);
ALTERNATIVE 3
Open the link in the android WebView
<WebView
android:id="#+id/webView"
android:layout_width="match_parent"
android:layout_height="match_parent" />
WebView webView= (WebView) findViewById(R.id.webView);
webView.loadUrl("http://ak-rt01.mni.thm.de:3000/#/playlist/57b03967e4da719c28d9fe2d");
short version :
instead of...
String videoUrl= "http://ak-rt01.mni.thm.de:3000/#/playlist/57b03967e4da719c28d9fe2d";
try using...
String videoUrl= "http://ak-rt01.mni.thm.de:3000/storage/playliststorage/57b03967e4da719c28d9fe2d/mainpanel/m1.m3u8";
long version :
"I want to stream this video from an Android app and I tried it with videoview and mediacontroller. But it's not working..."
Your videoUrl (http://ak-rt01.mni.thm.de:3000/#/playlist/57b03967e4da719c28d9fe2d) is actually accessing a .m3u8 playlist file. This list has streams of different video resolutions and you must load the relevant resolution's own .m3u8 for a playlist of .ts video files.
So try the following :
(1) : Load the streams.m3u8 as text (later can use String functions to extract relevant stream link)
http://ak-rt01.mni.thm.de:3000/storage/playliststorage/57b03967e4da719c28d9fe2d/mainpanel/streams.m3u8
and it will look like this :
#EXTM3U
#EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=720896,RESOLUTION=426x240
m1.m3u8
#EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=1048576,RESOLUTION=640x360
m2.m3u8
#EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=1376256,RESOLUTION=853x480
m3.m3u8
#EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=2031616,RESOLUTION=1024x576
m4.m3u8
#EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=2686976,RESOLUTION=1280x720
m5.m3u8
So from the above text we can deduce that 240p video is linked to m1.m3u8, or that 480p video is linked to m3.m3u8 and so on...
(2) : Suppose you want to play 240p (426 x 240) that will be m1.m3u8 so the link is :
http://ak-rt01.mni.thm.de:3000/storage/playliststorage/57b03967e4da719c28d9fe2d/mainpanel/m1.m3u8
For any other streams just replace the m1 part of above link with either m2, m3, m4, or m5.
(3) : Playing it Android... This is the tricky part for me to advise because I use Flash more to make my Android .apk apps (actually I'm here because you tagged Flash). You need to find the right Android SDK code examle for playing an m3u8 file.
You need to investigate : how to play m3u8 file in Android SDK
As a starting point try this possible solution. That code with your 240p looks like :
VideoView videoview = (VideoView)findViewById(R.id.myvideoview);
videoview.setMediaController(new MediaController(this));
videoview.setVideoURI(Uri.parse("http://ak-rt01.mni.thm.de:3000/storage/playliststorage/57b03967e4da719c28d9fe2d/mainpanel/m1.m3u8"));
videoview.requestFocus();
videoview.setOnPreparedListener(new OnPreparedListener() {
public void onPrepared(MediaPlayer mp) {
mp.start();
}
});
Another possible solution: link 1. All I can tell you is that Android can handle .ts video files and will accept a valid m3u8 URL.
I'm trying to create a activity with a Video Player.
The problem is that in some devices (ex. Android 4.0.4) when I try to play local video the VideoView shows LogCat error :
MediaPlayer(6757): Error (1,-2147483648)
And on screen:
"Cannot play video. Sorry, this video cannot be played"
The videos be recorded with MediaRecorder and this is the config of MediaRecorder
public boolean initRecorder(){
myRecorder = new MediaRecorder();
myRecorder.setCamera(myCamera);
myRecorder.setAudioSource(MediaRecorder.AudioSource.CAMCORDER);
myRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
myRecorder.setProfile(CamcorderProfile.get(CamcorderProfile.QUALITY_HIGH));
myRecorder.setOutputFile(getVideoFilePath()); //videopath.mp4
myRecorder.setVideoSize(size.width, size.height);
myRecorder.setPreviewDisplay(mySurfaceHolder.getSurface());
if(prepareRecorder()) return true;
else return false;
}
And played with VideoView like this:
VideoView vidDisplay = (VideoView) viewLayout.findViewById(R.id.vidDisplay);
Uri uri = Uri.parse(_imagePaths.get(position));
vidDisplay.setVideoURI(uri);
vidDisplay.setMediaController(new MediaController(_activity));
vidDisplay.requestFocus();
vidDisplay.start();
EDIT:
The problem is related to the user permissions of the video. Is there a way to create aguna videos with MediaRecorder with read permissions for everyone?
I tried to open the file and then make setReadable(true) but this not work
Can someone help me?
Thanks
I am getting error while playing video from asset folder and raw folder.
MediaPlayer error (1, -2147483648)
VideoView error 1, -2147483648.
I tried from asset folder as.
private String SrcPath = "file:///android_asset/aaa.mp4"; //also tried aaaa.mp3
VideoView vv = (VideoView)findViewById(R.id.videoView1);
vv.setVideoPath(SrcPath);
MediaController controller = new MediaController(this);
controller.setAnchorView(vv);
vv.setMediaController(controller);
vv.requestFocus();
vv.start();
and for raw folder i used URI as :
Uri video = Uri.parse("android.resource://com.usecontentprovider/raw/aaa.mp4");
vv.setVideoURI(video);
I got the same error message in both cases.
You can use software like avinaptic2 to get the video encoding information and make sure it matches the supported media formats in android.
A common problem I find is that videos are encoded with the wrong profiling. H.264 videos need to be encoded with Baseline level 3 or under to be played without errors or artifacts in Android.
I found the solution as I am able to play video on virtual device.
I replaced the line
Uri video = Uri.parse("android.resource://com.usecontentprovider/raw/aaa.mp4");
with
Uri video = Uri.parse("android.resource://com.usecontentprovider/raw/"+R.raw.aaa);
And its working
Using R.raw works fine but in some cases I still get the same error. Fortunately I found the solution to my problem: I had to call videoView.start() inside onPrepare().
You can check the correct answer here:
Android: 'Can't play this video'; MediaPlayer & VideoView Error 1 -38
I tried to play a RTSP stream "rtsp://217.146.95.166:554/playlist/ch27yqcif.3gp" (this stream tested on KM Player and it is alive)
and also tried to play from "m.youtube.com" but not success. It give me an error "Sorry this video cannot be played" when the program run.
here is my code.
VideoView videoView = (VideoView) findViewById(R.id.myvideoView);
MediaController mediaController = new MediaController(this);
mediaController.setAnchorView(videoView);
Uri video = Uri.parse("rtsp://217.146.95.166:554/playlist/ch27yqcif.3gp");
videoView.setMediaController(mediaController);
videoView.setVideoURI(video);
videoView.start();
The app run and download data for sometime and give me the error "Sorry this video cannot be played"
when I try this http link it play well.
http://3gpvideos.org/wp-content/uploads/2012/13/Ishq%20Mein%20Ruswaa%20Full%20Song.3gp
I tried so many different RTSP links and formats but not successful.
What is the wrong with this code.
log details..
05-16 08:52:38.633: D/MediaPlayer(275): Couldn't open file on client side, trying server side
05-16 08:53:52.272: W/MediaPlayer(275): info/warning (1, 26)
05-16 08:53:52.272: I/MediaPlayer(275): Info (1,26)
05-16 08:53:52.313: E/MediaPlayer(275): error (1, -1)
05-16 08:53:52.313: E/MediaPlayer(275): Error (1,-1)
05-16 08:53:52.313: D/VideoView(275): Error: 1,-1