2

I tried creating an app that allow users watch live stream videos on their android device. From my lil research I found out VLC Sdk is cool because it support more protocols. From the code gotten from Tutorial on using vlc sdk

I was able to make the live watching app works, but the issue is I can't seem to add a control (such as pause, play, seeker etc) to the video. Please I need you help. Thanks

vlc sdk used is 1.9.8

Prodigy
  • 2,094
  • 24
  • 30
  • Please clarify your doubt. Have you tried the same and not reached the conclusion or you want to know from scratch how to do the same? –  Jul 29 '17 at 07:57
  • Thanks @Mandy8055 I've tired adding mediacontroller but the api doesn't allow that. I've also surf the internet to see if i can see a sample but all to no avail – Prodigy Jul 29 '17 at 08:14
  • Have you tried this: https://github.com/mrmaffen/vlc-android-sdk/blob/master/src/main/java/org/videolan/libvlc/MediaPlayer.java ... Hope it works –  Jul 29 '17 at 08:16
  • was it helpful? –  Jul 29 '17 at 15:20
  • Thanks Mandy8055 for the time, it wasn't. It's the source code for the vlc lib – Prodigy Jul 29 '17 at 18:49

2 Answers2

2

Try this:

public class Show_Array extends AppCompatActivity implements IVLCVout.Callback  {

    private TextView container_extension;
    private String stream_typee,stream_idd,container_extensionn ;
    private String SAMPLE_URL = "";
    public int mHeight;
    public int mWidth;
    private SurfaceView mVideoSurface = null;
    private FrameLayout sdk;
    private IVLCVout vlcVout;
    private LibVLC mLibVlc = null;
    private MediaPlayer mMediaPlayer = null;
    private int flag = 0;
    private ImageButton Resize;
    private Media media;
    private ArrayList<String> args;
    private SurfaceHolder mSurfaceHolderVideo;
    private MediaController controller;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
        setContentView(R.layout.show__array);
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
        //Referances
        Resize = findViewById(R.id.Resize);
        mVideoSurface =  findViewById(R.id.video_surface);


        stream_typee = getIntent().getExtras().getString("stream_type");
        stream_idd = getIntent().getExtras().getString("stream_id");
        container_extensionn = getIntent().getExtras().getString("container_extension");

        args = new ArrayList<>();
        args.add("-vvv");
        mLibVlc = new LibVLC(this, args);
        mMediaPlayer = new MediaPlayer(mLibVlc);
        vlcVout = mMediaPlayer.getVLCVout();
        sdk = findViewById(R.id.sdk);


        Resize_video();
        setup_url();

        controller = new MediaController(this);
        controller.setMediaPlayer(playerInterface);
        controller.setAnchorView(mVideoSurface);
        mVideoSurface.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                controller.show(10000);
            }
        });

    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        mMediaPlayer.release();
        mLibVlc.release();
    }

    void Resize_video()
    {
        DisplayMetrics displayMetrics = new DisplayMetrics();
        getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
        mHeight = displayMetrics.heightPixels;
        mWidth = displayMetrics.widthPixels;
        Resize.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                flag+=1;
                int width = 1000;
                int height = 560;

                if(flag%2!=0) {

                    LinearLayout.LayoutParams myImageLayout = new LinearLayout.LayoutParams(width, height);
                    myImageLayout.gravity = Gravity.CENTER_HORIZONTAL | Gravity.CENTER_VERTICAL;
                    sdk.setLayoutParams(myImageLayout);
                    vlcVout.setWindowSize(width,height);

                }
                else
                {
                    LinearLayout.LayoutParams myImageLayout = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
                    myImageLayout.gravity = Gravity.CENTER_HORIZONTAL | Gravity.CENTER_VERTICAL;
                    sdk.setLayoutParams(myImageLayout);
                    vlcVout.setWindowSize(mWidth,mHeight);

                }
            }
        });
    }
    void setup_url()
    {
        //TextView
        container_extension = findViewById(R.id.URL);
        if (stream_typee.equals("live"))
        {
            SAMPLE_URL = "http://uautv.ru:2095/"+stream_typee+"/webserver/6tE@BzW73@sX/"+stream_idd+".ts";
            container_extension.setText( SAMPLE_URL);
        }else
        {
            SAMPLE_URL = "http://uautv.ru:2095/"+stream_typee+"/webserver/6tE@BzW73@sX/"+stream_idd+"."+container_extensionn;
            container_extension.setText( SAMPLE_URL);

        }
    }

    @Override
    protected void onStart() {
        super.onStart();
        vlcVout.setWindowSize(mWidth,mHeight);
        vlcVout.setVideoView(mVideoSurface);
        vlcVout.attachViews();
        mMediaPlayer.getVLCVout().addCallback(this);
        if(!SAMPLE_URL.isEmpty()) {
             media = new Media(mLibVlc, Uri.parse(SAMPLE_URL));
            mMediaPlayer.setMedia(media);
            media.release();
            mMediaPlayer.play();


        }else
        {
            Toast.makeText(getApplicationContext(),"URL EMPTY",Toast.LENGTH_LONG).show();
        }


    }

    @Override
    protected void onStop() {
        super.onStop();

        mMediaPlayer.stop();
        mMediaPlayer.getVLCVout().detachViews();
        mMediaPlayer.getVLCVout().removeCallback(this);


    }

    @TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
    @Override
    public void onNewLayout(IVLCVout vlcVout, int width, int height, int visibleWidth, int visibleHeight, int sarNum, int sarDen)
    { }

    @Override
    public void onSurfacesCreated(IVLCVout vlcVout) {
    }

    @Override
    public void onSurfacesDestroyed(IVLCVout vlcVout) {
    }
    private MediaController.MediaPlayerControl playerInterface = new MediaController.MediaPlayerControl() {
        public int getBufferPercentage() {
            return 0;
        }

        public int getCurrentPosition() {
            float pos = mMediaPlayer.getPosition();
            return (int)(pos * getDuration());
        }

        public int getDuration() {
            return (int)mMediaPlayer.getLength();
        }

        public boolean isPlaying() {
            return mMediaPlayer.isPlaying();
        }

        public void pause() {
            mMediaPlayer.pause();
        }

        public void seekTo(int pos) {
            mMediaPlayer.setPosition((float)pos / getDuration());
        }

        public void start() {
            mMediaPlayer.play();
        }

        public boolean canPause() {
            return true;
        }

        public boolean canSeekBackward() {
            return true;
        }

        public boolean canSeekForward() {
            return true;
        }

        @Override
        public int getAudioSessionId() {
            return 0;
        }
    };
}
Talha Rahman
  • 720
  • 4
  • 12
  • 27
  • This ought to be the selected answer as it's the most comprehensive solution (+ bonus points for working code). I used parts of this implementation to successfully add a MediaController to my LibVLC MediaPlayer (overlaid on the SurfaceView housing the video, with a nice little controller UI timeout). – Tom Larcher Jul 15 '19 at 01:27
0

I was looking into this as well. You need to implement this yourself.

Simply use FrameLayout and overlay a view ( button? ) per functionality on the video surface. Then make calls to the VLC MediaPlayer play() stop() pause() etc.

If you really want to dive deep then get the sources of the master, and see how it's done:

git clone https://code.videolan.org/videolan/vlc-android.git

RonTLV
  • 2,376
  • 2
  • 24
  • 38