0

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
TYL
  • 493
  • 2
  • 6
  • 19
  • Could you post some logs from your logcat. Usually when mediacontroller fails, It will print several warning or error logs. Worst case scenario, you could open the link in the web browser Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse("http://ak-rt01.mni.thm.de:3000/#/playlist/57b03967e4da719c28d9fe2d")); startActivity(i); – Adithya Upadhya Oct 30 '16 at 18:47
  • @oathkeeper I update the post. Can you identify anything? – TYL Oct 30 '16 at 19:00
  • I have added an answer in response to your query. The media controller hits the URL expecting a video but hits some html page instead. If you have any further doubts, please let me know... – Adithya Upadhya Oct 30 '16 at 19:33
  • @oathkeeper thank you for quickly and informative answer. I will test all the three alternatives to feasibility. You are super.. I wasted 2 days for this code. Thank you! (I would click at "usefull answer" but I have not 15 reputation.) – TYL Oct 30 '16 at 19:44
  • Sure, any time :) . Let me know if you get stuck somewhere else. Test your code with this URL http://techslides.com/demos/sample-videos/small.mp4 . It contains a valid video URL. – Adithya Upadhya Oct 30 '16 at 19:48
  • #PS: I just saw notification you were trying to edit my Answer. What's the problem? If you change the words, how can it help others with exact same problem in future? – VC.One Feb 18 '17 at 08:32
  • I had to change the url because of data protection reasons. For people who have similar problems. The URL had not a .mp4 ; mp3; or similar format. I have abridged the url only in this answer. – TYL Feb 19 '17 at 12:12

2 Answers2

0

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");
Adithya Upadhya
  • 2,239
  • 20
  • 28
0

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.

Community
  • 1
  • 1
VC.One
  • 14,790
  • 4
  • 25
  • 57