Want to create app, to stream from a url in android - android

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.

Related

Android VideoView not working in sdk 4.3

I am trying to play a video from the device on a VideoView. Here is my code:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
vView = (VideoView) findViewById(R.id.videoView);
mc = new MediaController(this);
vView.setMediaController(mc);
String new_emulator_path = "/storage/emulated/0/Download/testvid.mp4";
Uri uri = Uri.parse(new_emulator_path);
vView.setVideoURI(uri);
vView.requestFocus();
mc.show();
vView.start();
}
...
<VideoView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/videoView"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"
android:adjustViewBounds="true" />
While using the same code on 5.1 it plays fine, but does not play in 4.3 and below. Following is the log extract:
04-30 00:28:09.141 2293-2293/com.ebook.video D/MediaPlayer: getMetadata
04-30 00:28:09.249 2293-2314/com.ebook.video E/MediaPlayer: error (1, -2147483648)
04-30 00:28:09.257 2293-2293/com.ebook.video E/MediaPlayer: Error (1,-2147483648)
04-30 00:28:09.257 2293-2293/com.ebook.video D/VideoView: Error: 1,-2147483648
I have seen many threads in regard to this error code, but could not comprehend any explanations.
EDIT: I have tried playing videos of different formats - mkv (H264 mpeg-4 AVC) , 3gp (H263), mp4 (H264 mpeg-4 AVC), flv (FLV1). Video with 3gp extension and H263 format plays fine, while others give the error message as mentioned above. Any ideas on how to resolve this ?
According to Documentation Android not support H265 before android 5.1
So I think you have issue with this. You can use ExoPlayer (Or better way ExoMedia simple wrapper around VideoPlayer & ExoPlayer).
BTW use following piece of code may helps you :
VideoView videoView = (VideoView) findViewById(R.id.videoView1);
videoView.setVideoPath(YOUR_LOCAL_FILE_PATH);
MediaController mediaController = new MediaController(this);
mediaController.setAnchorView(videoView);
videoView.setMediaController(mediaController);
videoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
#Override
public void onPrepared(MediaPlayer mp) {
Log.i(TAG,"Hoooray");
}
});
videoView.start();
As I found out from your code you want to display video in emulator so first see this related post.

Android VideoView does not accept RTSP URI

Long-time user, first time poster. So thanks already to everyone who has helped on here, directly or indirectly before.
I'm having issues trying to stream an mp4/3gp video file which is being served over RTSP. The code for my POC is below, but is pretty much identical to the example I found here:
http://android-coding.blogspot.co.uk/2011/03/simple-example-using-videoview-to-play.html
String rtspLink = "rtsp://v5.cache1.c.youtube.com/CjYLENy73wIaLQnhycnrJQ8qmRMYESARFEIJbXYtZ29vZ2xlSARSBXdhdGNoYPj_hYjnq6uUTQw=/0/0/0/video.3gp";
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_vid_view_rtsp);
VideoView myVideoView = (VideoView)findViewById(R.id.myvideoview);
myVideoView.setVideoURI(Uri.parse(rtspLink));
myVideoView.setMediaController(new MediaController(this));
myVideoView.requestFocus();
myVideoView.start();
}
Unfortunately, most of the examples I found are from a few years ago, this one in particular being from 2011. I am testing on a physical Samsung S3 (Android 4.3).
I have confirmed that the 3gp file does exist, and have successfully streamed it using VLC. I have the same issue with my own MP4's.
The stack trace/logcat generated is as follows:
09-15 02:16:07.520 25040-25040/org.chutchut.videoviewrtsp D/MediaPlayer﹕ setDataSource IOException happend :
java.io.FileNotFoundException: No content provider: rtsp://v5.cache1.c.youtube.com/CjYLENy73wIaLQnhycnrJQ8qmRMYESARFEIJbXYtZ29vZ2xlSARSBXdhdGNoYPj_hYjnq6uUTQw=/0/0/0/video.3gp
at android.content.ContentResolver.openTypedAssetFileDescriptor(ContentResolver.java:761)
at android.content.ContentResolver.openAssetFileDescriptor(ContentResolver.java:665)
at android.media.MediaPlayer.setDataSource(MediaPlayer.java:960)
at android.widget.VideoView.openVideo(VideoView.java:264)
at android.widget.VideoView.access$2000(VideoView.java:52)
at android.widget.VideoView$6.surfaceCreated(VideoView.java:522)
<.. snip ..>
09-15 02:16:07.520 25040-25040/org.chutchut.videoviewrtsp D/MediaPlayer﹕ Couldn't open file on client side, trying server side
09-15 02:16:07.530 25040-25040/org.chutchut.videoviewrtsp E/MediaPlayer﹕ Unable to to create media player
09-15 02:16:07.535 25040-25040/org.chutchut.videoviewrtsp W/VideoView﹕ Unable to open content: rtsp://v5.cache1.c.youtube.com/CjYLENy73wIaLQnhycnrJQ8qmRMYESARFEIJbXYtZ29vZ2xlSARSBXdhdGNoYPj_hYjnq6uUTQw=/0/0/0/video.3gp
java.io.IOException: setDataSource failed.: status=0x80000000
at android.media.MediaPlayer._setDataSource(Native Method)
at android.media.MediaPlayer.setDataSource(MediaPlayer.java:1185)
at android.media.MediaPlayer.setDataSource(MediaPlayer.java:1130)
at android.media.MediaPlayer.setDataSource(MediaPlayer.java:989)
at android.widget.VideoView.openVideo(VideoView.java:264)
at android.widget.VideoView.access$2000(VideoView.java:52)
at android.widget.VideoView$6.surfaceCreated(VideoView.java:522)
<.. snip ..>
09-15 02:16:07.535 25040-25040/org.chutchut.videoviewrtsp D/VideoView﹕ Error: 1,0
Thanks in advance!

Dynamic Http Streaming in Android to play live Flash video

I am trying to connect my android application with FTP Server which is broadcasting multiple streams using Dynamic Http Streaming at different bit rates.Flash Messaging Server(FMS) is using H.264 codec to broadcast video in flv format.On client side(Android) I am getting f4m(manifest (xml) file)) having diffrent streams.
I am unable to use the f4m file to fetch video in android from FMS.
String url = "http://d2233avv69kunu.cloudfront.net/hds-live/livepkgr/_definst_/liveevent/livestream.f4m";
Uri uri = Uri.parse(url);
// videoView.setVideoURI(uri);
videoView.setVideoPath(str);
MediaController mc = new MediaController(this);
//VMRuntime.getRuntime().setMinimumHeapSize(40);
mc.setAnchorView(videoView);
videoView.setMediaController(mc);
System.out.println("Max Memory - "+java.lang.Runtime.getRuntime().maxMemory());
videoView.requestFocus();
videoView.setOnPreparedListener(new OnPreparedListener()
{
public void onPrepared(MediaPlayer mp)
{
videoView.start();
}
});
In above code I am trying to run video in Video View component by passing link of f4m file.
Flash encoder convert video into 3 file formats as listed below
.f4m (manifest files) - Bootstrap Info,Metadata, Bitrate, Flash Access license Server location
.f4f (fragment files) - extends the F4V format,MP4 fragment std
.f4x (index files) - binary
Kindly provide solution to play video on different android devices via Http Streaming in android.
Thanks in advance.
1) You have left something out of your code. What is str that you are passing to setVideoPath? (this is somewhat irrelevant, though...)
2) The MediaPlayer (and thereby VideoView) cannot play Flash video at all. It's simply not supported. It definitely won't understand an XML file, either, so passing it the f4m file is pointless.

Can't Play RTSP Stream (3gp encode) on Android 2.2

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

Opening RTSP video in VideoView

I wan't to open a .3gp video that is hosted on a remote server in a VideoView inside my app. The protocol used is RTSP. I keep getting this error:
04-07 19:26:32.528: E/MediaPlayer(7358): Unable to to create media player
04-07 19:26:32.536: W/VideoView(7358): Unable to open content: rtsp://v2.cache1.c.youtube.com/CiULENy73wIaHAk-BOiQ3AO9gBMYDSANFEgGUglwbGF5bGlzdHMM/0/0/0/video.3gp
04-07 19:26:32.536: W/VideoView(7358): java.io.IOException: setDataSource failed.: status=0x80000000
The stream is working and the codec should be supported. Can't locate the problem. I've tried it on a Sony GTV box and on a ICS tablet.
This is the code I'm using:
videoview.setVideoURI(Uri.parse(viduri));
MediaController mc = new MediaController(PlayerActivity.this);
videoview.setMediaController(mc);
videoview.requestFocus();
videoview.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
public void onPrepared(MediaPlayer arg0) {
progressBar.setVisibility(View.GONE);
videoview.start();
}
});
Does anyone have experience with the same issue? Any solutions? The error message isn't very helpful...
What I see is that this stream can't be found. Are you obtaining this Youtube video using YouTube Data API?

Categories

Resources