Search code examples
androidstreamvlc

Android - m3u8 video streaming


I am streaming live video in my app. I have a .m3u8 link, which works perfectly in vlc player. But when I am playing this stream in my app, the visualisation of video is damaged (see screenshot). Does anybody know, what could cause this?damaged video

EDIT: I realised that this occurs only on the Android 8.1.


Solution

  • Try this library for .m3u8 , this will solve your problem :

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
                    xmlns:app="http://schemas.android.com/apk/res-auto"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent">
    
        <com.devbrackets.android.exomedia.ui.widget.VideoView
            android:id="@+id/video_view"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:useDefaultControls="true"/>
    
    </RelativeLayout>
    

    In Activity write below code

    private VideoView videoView;
    
    private void setupVideoView() {
        // Make sure to use the correct VideoView import
        videoView = (VideoView)findViewById(R.id.video_view);
        videoView.setOnPreparedListener(this);
    
        //For now we just picked an arbitrary item to play
        videoView.setVideoURI(Uri.parse("https://archive.org/download/Popeye_forPresident/Popeye_forPresident_512kb.m3u8"));
    }
    
    @Override
    public void onPrepared() {
        //Starts the video playback as soon as it is ready
        videoView.start();
    }