Getting current frame from android vlc media player










0














I'm using VLC-Android in order to play H264 RTSP live stream in my android application, the following code successfully renders the stream video onto the surface view:



MediaPlayer mMediaPlayer = new MediaPlayer(VLCInstance.get());
SurfaceView mSurfaceView = (SurfaceView) findViewById(R.id.player);

final IVLCVout vlcVout = Constants.mMediaPlayer.getVLCVout();
vlcVout.detachViews();
vlcVout.setVideoView(mSurfaceView);
vlcVout.setWindowSize(mSurfaceDims.getWidth(), mSurfaceDims.getHeight());
vlcVout.attachViews();
mSurfaceView.setKeepScreenOn(true);

Media media = new Media(VLCInstance.get(), Uri.parse(path));
mMediaPlayer.setMedia(media);
mMediaPlayer.play();


VLCInstance.java:



package bi.anpr.vlc;

import android.content.Context;
import android.util.Log;

import org.videolan.libvlc.LibVLC;
import org.videolan.libvlc.util.VLCUtil;

public class VLCInstance
public final static String TAG = "VLC/Util/VLCInstance";

private static LibVLC sLibVLC = null;

/** A set of utility functions for the VLC application */
public synchronized static LibVLC get() throws IllegalStateException
if (sLibVLC == null)
final Context context = VLCApplication.getAppContext();
if(!VLCUtil.hasCompatibleCPU(context))
Log.e(TAG, VLCUtil.getErrorMsg());
throw new IllegalStateException("LibVLC initialisation failed: " + VLCUtil.getErrorMsg());


try
sLibVLC = new LibVLC(context);
catch (Throwable e)
e.printStackTrace();



return sLibVLC;


public static synchronized void restart(Context context) throws IllegalStateException
if (sLibVLC != null)
sLibVLC.release();
sLibVLC = new LibVLC(context);





The problem is that the org.videolan.libvlc.MediaPlayer renders the video on the SurfaceView after calling play() without any event that helps you to grab the current frame on the view, where i need to get the current frame each interval of time to perform some image processing on it.



So is it possible using vlc-android-sdk to grab current frame, into a buffered image or an OpenCV Mat, while playing live streams or local video resources?



Note that it is possible with java (desktop vlcj) through the DirectMediaPlayer class.



Thanks in advance!!










share|improve this question























  • Check this videolan.org/developers/vlc/doc/doxygen/html/…
    – mtz
    Nov 12 '18 at 2:51










  • did you find any solution?
    – Anjani Mittal
    Nov 20 '18 at 10:17










  • @AnjaniMittal yes I do without any aid neither from the VLC nor from the community, I will post the answer tomorrow hopefully, i'm just still making some tests
    – peter bence
    Nov 21 '18 at 14:24










  • sure thnx, but I found an alternative today, using PixelCopy to fetch the screenshot of surface view and it's not blank, it's working totally fine, tried it. Hope this helps.
    – Anjani Mittal
    Nov 22 '18 at 9:38










  • thanks @AnjaniMittal, please check my answer i think it would be much faster than using any third party tool
    – peter bence
    Nov 22 '18 at 10:27















0














I'm using VLC-Android in order to play H264 RTSP live stream in my android application, the following code successfully renders the stream video onto the surface view:



MediaPlayer mMediaPlayer = new MediaPlayer(VLCInstance.get());
SurfaceView mSurfaceView = (SurfaceView) findViewById(R.id.player);

final IVLCVout vlcVout = Constants.mMediaPlayer.getVLCVout();
vlcVout.detachViews();
vlcVout.setVideoView(mSurfaceView);
vlcVout.setWindowSize(mSurfaceDims.getWidth(), mSurfaceDims.getHeight());
vlcVout.attachViews();
mSurfaceView.setKeepScreenOn(true);

Media media = new Media(VLCInstance.get(), Uri.parse(path));
mMediaPlayer.setMedia(media);
mMediaPlayer.play();


VLCInstance.java:



package bi.anpr.vlc;

import android.content.Context;
import android.util.Log;

import org.videolan.libvlc.LibVLC;
import org.videolan.libvlc.util.VLCUtil;

public class VLCInstance
public final static String TAG = "VLC/Util/VLCInstance";

private static LibVLC sLibVLC = null;

/** A set of utility functions for the VLC application */
public synchronized static LibVLC get() throws IllegalStateException
if (sLibVLC == null)
final Context context = VLCApplication.getAppContext();
if(!VLCUtil.hasCompatibleCPU(context))
Log.e(TAG, VLCUtil.getErrorMsg());
throw new IllegalStateException("LibVLC initialisation failed: " + VLCUtil.getErrorMsg());


try
sLibVLC = new LibVLC(context);
catch (Throwable e)
e.printStackTrace();



return sLibVLC;


public static synchronized void restart(Context context) throws IllegalStateException
if (sLibVLC != null)
sLibVLC.release();
sLibVLC = new LibVLC(context);





The problem is that the org.videolan.libvlc.MediaPlayer renders the video on the SurfaceView after calling play() without any event that helps you to grab the current frame on the view, where i need to get the current frame each interval of time to perform some image processing on it.



So is it possible using vlc-android-sdk to grab current frame, into a buffered image or an OpenCV Mat, while playing live streams or local video resources?



Note that it is possible with java (desktop vlcj) through the DirectMediaPlayer class.



Thanks in advance!!










share|improve this question























  • Check this videolan.org/developers/vlc/doc/doxygen/html/…
    – mtz
    Nov 12 '18 at 2:51










  • did you find any solution?
    – Anjani Mittal
    Nov 20 '18 at 10:17










  • @AnjaniMittal yes I do without any aid neither from the VLC nor from the community, I will post the answer tomorrow hopefully, i'm just still making some tests
    – peter bence
    Nov 21 '18 at 14:24










  • sure thnx, but I found an alternative today, using PixelCopy to fetch the screenshot of surface view and it's not blank, it's working totally fine, tried it. Hope this helps.
    – Anjani Mittal
    Nov 22 '18 at 9:38










  • thanks @AnjaniMittal, please check my answer i think it would be much faster than using any third party tool
    – peter bence
    Nov 22 '18 at 10:27













0












0








0







I'm using VLC-Android in order to play H264 RTSP live stream in my android application, the following code successfully renders the stream video onto the surface view:



MediaPlayer mMediaPlayer = new MediaPlayer(VLCInstance.get());
SurfaceView mSurfaceView = (SurfaceView) findViewById(R.id.player);

final IVLCVout vlcVout = Constants.mMediaPlayer.getVLCVout();
vlcVout.detachViews();
vlcVout.setVideoView(mSurfaceView);
vlcVout.setWindowSize(mSurfaceDims.getWidth(), mSurfaceDims.getHeight());
vlcVout.attachViews();
mSurfaceView.setKeepScreenOn(true);

Media media = new Media(VLCInstance.get(), Uri.parse(path));
mMediaPlayer.setMedia(media);
mMediaPlayer.play();


VLCInstance.java:



package bi.anpr.vlc;

import android.content.Context;
import android.util.Log;

import org.videolan.libvlc.LibVLC;
import org.videolan.libvlc.util.VLCUtil;

public class VLCInstance
public final static String TAG = "VLC/Util/VLCInstance";

private static LibVLC sLibVLC = null;

/** A set of utility functions for the VLC application */
public synchronized static LibVLC get() throws IllegalStateException
if (sLibVLC == null)
final Context context = VLCApplication.getAppContext();
if(!VLCUtil.hasCompatibleCPU(context))
Log.e(TAG, VLCUtil.getErrorMsg());
throw new IllegalStateException("LibVLC initialisation failed: " + VLCUtil.getErrorMsg());


try
sLibVLC = new LibVLC(context);
catch (Throwable e)
e.printStackTrace();



return sLibVLC;


public static synchronized void restart(Context context) throws IllegalStateException
if (sLibVLC != null)
sLibVLC.release();
sLibVLC = new LibVLC(context);





The problem is that the org.videolan.libvlc.MediaPlayer renders the video on the SurfaceView after calling play() without any event that helps you to grab the current frame on the view, where i need to get the current frame each interval of time to perform some image processing on it.



So is it possible using vlc-android-sdk to grab current frame, into a buffered image or an OpenCV Mat, while playing live streams or local video resources?



Note that it is possible with java (desktop vlcj) through the DirectMediaPlayer class.



Thanks in advance!!










share|improve this question















I'm using VLC-Android in order to play H264 RTSP live stream in my android application, the following code successfully renders the stream video onto the surface view:



MediaPlayer mMediaPlayer = new MediaPlayer(VLCInstance.get());
SurfaceView mSurfaceView = (SurfaceView) findViewById(R.id.player);

final IVLCVout vlcVout = Constants.mMediaPlayer.getVLCVout();
vlcVout.detachViews();
vlcVout.setVideoView(mSurfaceView);
vlcVout.setWindowSize(mSurfaceDims.getWidth(), mSurfaceDims.getHeight());
vlcVout.attachViews();
mSurfaceView.setKeepScreenOn(true);

Media media = new Media(VLCInstance.get(), Uri.parse(path));
mMediaPlayer.setMedia(media);
mMediaPlayer.play();


VLCInstance.java:



package bi.anpr.vlc;

import android.content.Context;
import android.util.Log;

import org.videolan.libvlc.LibVLC;
import org.videolan.libvlc.util.VLCUtil;

public class VLCInstance
public final static String TAG = "VLC/Util/VLCInstance";

private static LibVLC sLibVLC = null;

/** A set of utility functions for the VLC application */
public synchronized static LibVLC get() throws IllegalStateException
if (sLibVLC == null)
final Context context = VLCApplication.getAppContext();
if(!VLCUtil.hasCompatibleCPU(context))
Log.e(TAG, VLCUtil.getErrorMsg());
throw new IllegalStateException("LibVLC initialisation failed: " + VLCUtil.getErrorMsg());


try
sLibVLC = new LibVLC(context);
catch (Throwable e)
e.printStackTrace();



return sLibVLC;


public static synchronized void restart(Context context) throws IllegalStateException
if (sLibVLC != null)
sLibVLC.release();
sLibVLC = new LibVLC(context);





The problem is that the org.videolan.libvlc.MediaPlayer renders the video on the SurfaceView after calling play() without any event that helps you to grab the current frame on the view, where i need to get the current frame each interval of time to perform some image processing on it.



So is it possible using vlc-android-sdk to grab current frame, into a buffered image or an OpenCV Mat, while playing live streams or local video resources?



Note that it is possible with java (desktop vlcj) through the DirectMediaPlayer class.



Thanks in advance!!







android vlc libvlc vlc-android






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Dec 23 '18 at 11:15









caprica

2,60531333




2,60531333










asked Nov 10 '18 at 12:18









peter bence

5510




5510











  • Check this videolan.org/developers/vlc/doc/doxygen/html/…
    – mtz
    Nov 12 '18 at 2:51










  • did you find any solution?
    – Anjani Mittal
    Nov 20 '18 at 10:17










  • @AnjaniMittal yes I do without any aid neither from the VLC nor from the community, I will post the answer tomorrow hopefully, i'm just still making some tests
    – peter bence
    Nov 21 '18 at 14:24










  • sure thnx, but I found an alternative today, using PixelCopy to fetch the screenshot of surface view and it's not blank, it's working totally fine, tried it. Hope this helps.
    – Anjani Mittal
    Nov 22 '18 at 9:38










  • thanks @AnjaniMittal, please check my answer i think it would be much faster than using any third party tool
    – peter bence
    Nov 22 '18 at 10:27
















  • Check this videolan.org/developers/vlc/doc/doxygen/html/…
    – mtz
    Nov 12 '18 at 2:51










  • did you find any solution?
    – Anjani Mittal
    Nov 20 '18 at 10:17










  • @AnjaniMittal yes I do without any aid neither from the VLC nor from the community, I will post the answer tomorrow hopefully, i'm just still making some tests
    – peter bence
    Nov 21 '18 at 14:24










  • sure thnx, but I found an alternative today, using PixelCopy to fetch the screenshot of surface view and it's not blank, it's working totally fine, tried it. Hope this helps.
    – Anjani Mittal
    Nov 22 '18 at 9:38










  • thanks @AnjaniMittal, please check my answer i think it would be much faster than using any third party tool
    – peter bence
    Nov 22 '18 at 10:27















Check this videolan.org/developers/vlc/doc/doxygen/html/…
– mtz
Nov 12 '18 at 2:51




Check this videolan.org/developers/vlc/doc/doxygen/html/…
– mtz
Nov 12 '18 at 2:51












did you find any solution?
– Anjani Mittal
Nov 20 '18 at 10:17




did you find any solution?
– Anjani Mittal
Nov 20 '18 at 10:17












@AnjaniMittal yes I do without any aid neither from the VLC nor from the community, I will post the answer tomorrow hopefully, i'm just still making some tests
– peter bence
Nov 21 '18 at 14:24




@AnjaniMittal yes I do without any aid neither from the VLC nor from the community, I will post the answer tomorrow hopefully, i'm just still making some tests
– peter bence
Nov 21 '18 at 14:24












sure thnx, but I found an alternative today, using PixelCopy to fetch the screenshot of surface view and it's not blank, it's working totally fine, tried it. Hope this helps.
– Anjani Mittal
Nov 22 '18 at 9:38




sure thnx, but I found an alternative today, using PixelCopy to fetch the screenshot of surface view and it's not blank, it's working totally fine, tried it. Hope this helps.
– Anjani Mittal
Nov 22 '18 at 9:38












thanks @AnjaniMittal, please check my answer i think it would be much faster than using any third party tool
– peter bence
Nov 22 '18 at 10:27




thanks @AnjaniMittal, please check my answer i think it would be much faster than using any third party tool
– peter bence
Nov 22 '18 at 10:27












1 Answer
1






active

oldest

votes


















0














I'd found a very simple an very fast solution to do this. Just use a TextureView instead of a SurfaceView, and then retrieve the image anytime while playing using the getBitmap() function as shown below.



public class MainActivity extends AppCompatActivity implements TextureView.SurfaceTextureListener,
org.videolan.libvlc.media.MediaPlayer.OnBufferingUpdateListener,
org.videolan.libvlc.media.MediaPlayer.OnCompletionListener,
org.videolan.libvlc.media.MediaPlayer.OnPreparedListener,
org.videolan.libvlc.media.MediaPlayer.OnVideoSizeChangedListener

private AppCompatActivity me = this;
private MediaPlayer mMediaPlayer;
private TextureView mTextureViewmTextureView;
private String mUrl = "/storage/emulated/0/videos/test.mp4";
private static final String TAG = "MainActivity";

@Override
protected void onCreate(Bundle savedInstanceState)
super.onCreate(savedInstanceState);
setContentView(R.layout.content_main);

mMediaPlayer = new MediaPlayer(VLCInstance.get());
mTextureViewmTextureView = (TextureView) findViewById(R.id.player);
mTextureView.setSurfaceTextureListener(this);


private void attachViewSurface()
final IVLCVout vlcVout = mMediaPlayer.getVLCVout();
mMediaPlayer.setScale(0);
vlcVout.detachViews();
vlcVout.setVideoView(mTextureView);
vlcVout.setWindowSize(mTextureView.getWidth(), mTextureView.getHeight());
vlcVout.attachViews();
mTextureView.setKeepScreenOn(true);



private void play(String path)
try
Media media;
if (new File(path).exists())
media = new Media(VLCInstance.get(), path);
else
media = new Media(VLCInstance.get(), Uri.parse(path));


mMediaPlayer.setMedia(media);
mMediaPlayer.play();
catch (Exception e)
Log.e(TAG, e.getMessage());



@Override
public void onSurfaceTextureAvailable(SurfaceTexture surface, int width, int height)
attachViewSurface();

if (mMediaPlayer.hasMedia())
mMediaPlayer.play();
else
play(mUrl);


public Bitmap getImage()
return mTextureView.getBitmap();





VLCInstance.java:



import android.content.Context;
import android.util.Log;

import org.videolan.libvlc.LibVLC;
import org.videolan.libvlc.util.VLCUtil;

public class VLCInstance
public final static String TAG = "VLC/Util/VLCInstance";

private static LibVLC sLibVLC = null;

/** A set of utility functions for the VLC application */
public synchronized static LibVLC get() throws IllegalStateException
if (sLibVLC == null)
final Context context = VLCApplication.getAppContext();
if(!VLCUtil.hasCompatibleCPU(context))
Log.e(TAG, VLCUtil.getErrorMsg());
throw new IllegalStateException("LibVLC initialisation failed: " + VLCUtil.getErrorMsg());


try
sLibVLC = new LibVLC(context);
catch (Throwable e)
e.printStackTrace();



return sLibVLC;


public static synchronized void restart(Context context) throws IllegalStateException
if (sLibVLC != null)
sLibVLC.release();
sLibVLC = new LibVLC(context);








share|improve this answer




















    Your Answer






    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "1"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53238880%2fgetting-current-frame-from-android-vlc-media-player%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    I'd found a very simple an very fast solution to do this. Just use a TextureView instead of a SurfaceView, and then retrieve the image anytime while playing using the getBitmap() function as shown below.



    public class MainActivity extends AppCompatActivity implements TextureView.SurfaceTextureListener,
    org.videolan.libvlc.media.MediaPlayer.OnBufferingUpdateListener,
    org.videolan.libvlc.media.MediaPlayer.OnCompletionListener,
    org.videolan.libvlc.media.MediaPlayer.OnPreparedListener,
    org.videolan.libvlc.media.MediaPlayer.OnVideoSizeChangedListener

    private AppCompatActivity me = this;
    private MediaPlayer mMediaPlayer;
    private TextureView mTextureViewmTextureView;
    private String mUrl = "/storage/emulated/0/videos/test.mp4";
    private static final String TAG = "MainActivity";

    @Override
    protected void onCreate(Bundle savedInstanceState)
    super.onCreate(savedInstanceState);
    setContentView(R.layout.content_main);

    mMediaPlayer = new MediaPlayer(VLCInstance.get());
    mTextureViewmTextureView = (TextureView) findViewById(R.id.player);
    mTextureView.setSurfaceTextureListener(this);


    private void attachViewSurface()
    final IVLCVout vlcVout = mMediaPlayer.getVLCVout();
    mMediaPlayer.setScale(0);
    vlcVout.detachViews();
    vlcVout.setVideoView(mTextureView);
    vlcVout.setWindowSize(mTextureView.getWidth(), mTextureView.getHeight());
    vlcVout.attachViews();
    mTextureView.setKeepScreenOn(true);



    private void play(String path)
    try
    Media media;
    if (new File(path).exists())
    media = new Media(VLCInstance.get(), path);
    else
    media = new Media(VLCInstance.get(), Uri.parse(path));


    mMediaPlayer.setMedia(media);
    mMediaPlayer.play();
    catch (Exception e)
    Log.e(TAG, e.getMessage());



    @Override
    public void onSurfaceTextureAvailable(SurfaceTexture surface, int width, int height)
    attachViewSurface();

    if (mMediaPlayer.hasMedia())
    mMediaPlayer.play();
    else
    play(mUrl);


    public Bitmap getImage()
    return mTextureView.getBitmap();





    VLCInstance.java:



    import android.content.Context;
    import android.util.Log;

    import org.videolan.libvlc.LibVLC;
    import org.videolan.libvlc.util.VLCUtil;

    public class VLCInstance
    public final static String TAG = "VLC/Util/VLCInstance";

    private static LibVLC sLibVLC = null;

    /** A set of utility functions for the VLC application */
    public synchronized static LibVLC get() throws IllegalStateException
    if (sLibVLC == null)
    final Context context = VLCApplication.getAppContext();
    if(!VLCUtil.hasCompatibleCPU(context))
    Log.e(TAG, VLCUtil.getErrorMsg());
    throw new IllegalStateException("LibVLC initialisation failed: " + VLCUtil.getErrorMsg());


    try
    sLibVLC = new LibVLC(context);
    catch (Throwable e)
    e.printStackTrace();



    return sLibVLC;


    public static synchronized void restart(Context context) throws IllegalStateException
    if (sLibVLC != null)
    sLibVLC.release();
    sLibVLC = new LibVLC(context);








    share|improve this answer

























      0














      I'd found a very simple an very fast solution to do this. Just use a TextureView instead of a SurfaceView, and then retrieve the image anytime while playing using the getBitmap() function as shown below.



      public class MainActivity extends AppCompatActivity implements TextureView.SurfaceTextureListener,
      org.videolan.libvlc.media.MediaPlayer.OnBufferingUpdateListener,
      org.videolan.libvlc.media.MediaPlayer.OnCompletionListener,
      org.videolan.libvlc.media.MediaPlayer.OnPreparedListener,
      org.videolan.libvlc.media.MediaPlayer.OnVideoSizeChangedListener

      private AppCompatActivity me = this;
      private MediaPlayer mMediaPlayer;
      private TextureView mTextureViewmTextureView;
      private String mUrl = "/storage/emulated/0/videos/test.mp4";
      private static final String TAG = "MainActivity";

      @Override
      protected void onCreate(Bundle savedInstanceState)
      super.onCreate(savedInstanceState);
      setContentView(R.layout.content_main);

      mMediaPlayer = new MediaPlayer(VLCInstance.get());
      mTextureViewmTextureView = (TextureView) findViewById(R.id.player);
      mTextureView.setSurfaceTextureListener(this);


      private void attachViewSurface()
      final IVLCVout vlcVout = mMediaPlayer.getVLCVout();
      mMediaPlayer.setScale(0);
      vlcVout.detachViews();
      vlcVout.setVideoView(mTextureView);
      vlcVout.setWindowSize(mTextureView.getWidth(), mTextureView.getHeight());
      vlcVout.attachViews();
      mTextureView.setKeepScreenOn(true);



      private void play(String path)
      try
      Media media;
      if (new File(path).exists())
      media = new Media(VLCInstance.get(), path);
      else
      media = new Media(VLCInstance.get(), Uri.parse(path));


      mMediaPlayer.setMedia(media);
      mMediaPlayer.play();
      catch (Exception e)
      Log.e(TAG, e.getMessage());



      @Override
      public void onSurfaceTextureAvailable(SurfaceTexture surface, int width, int height)
      attachViewSurface();

      if (mMediaPlayer.hasMedia())
      mMediaPlayer.play();
      else
      play(mUrl);


      public Bitmap getImage()
      return mTextureView.getBitmap();





      VLCInstance.java:



      import android.content.Context;
      import android.util.Log;

      import org.videolan.libvlc.LibVLC;
      import org.videolan.libvlc.util.VLCUtil;

      public class VLCInstance
      public final static String TAG = "VLC/Util/VLCInstance";

      private static LibVLC sLibVLC = null;

      /** A set of utility functions for the VLC application */
      public synchronized static LibVLC get() throws IllegalStateException
      if (sLibVLC == null)
      final Context context = VLCApplication.getAppContext();
      if(!VLCUtil.hasCompatibleCPU(context))
      Log.e(TAG, VLCUtil.getErrorMsg());
      throw new IllegalStateException("LibVLC initialisation failed: " + VLCUtil.getErrorMsg());


      try
      sLibVLC = new LibVLC(context);
      catch (Throwable e)
      e.printStackTrace();



      return sLibVLC;


      public static synchronized void restart(Context context) throws IllegalStateException
      if (sLibVLC != null)
      sLibVLC.release();
      sLibVLC = new LibVLC(context);








      share|improve this answer























        0












        0








        0






        I'd found a very simple an very fast solution to do this. Just use a TextureView instead of a SurfaceView, and then retrieve the image anytime while playing using the getBitmap() function as shown below.



        public class MainActivity extends AppCompatActivity implements TextureView.SurfaceTextureListener,
        org.videolan.libvlc.media.MediaPlayer.OnBufferingUpdateListener,
        org.videolan.libvlc.media.MediaPlayer.OnCompletionListener,
        org.videolan.libvlc.media.MediaPlayer.OnPreparedListener,
        org.videolan.libvlc.media.MediaPlayer.OnVideoSizeChangedListener

        private AppCompatActivity me = this;
        private MediaPlayer mMediaPlayer;
        private TextureView mTextureViewmTextureView;
        private String mUrl = "/storage/emulated/0/videos/test.mp4";
        private static final String TAG = "MainActivity";

        @Override
        protected void onCreate(Bundle savedInstanceState)
        super.onCreate(savedInstanceState);
        setContentView(R.layout.content_main);

        mMediaPlayer = new MediaPlayer(VLCInstance.get());
        mTextureViewmTextureView = (TextureView) findViewById(R.id.player);
        mTextureView.setSurfaceTextureListener(this);


        private void attachViewSurface()
        final IVLCVout vlcVout = mMediaPlayer.getVLCVout();
        mMediaPlayer.setScale(0);
        vlcVout.detachViews();
        vlcVout.setVideoView(mTextureView);
        vlcVout.setWindowSize(mTextureView.getWidth(), mTextureView.getHeight());
        vlcVout.attachViews();
        mTextureView.setKeepScreenOn(true);



        private void play(String path)
        try
        Media media;
        if (new File(path).exists())
        media = new Media(VLCInstance.get(), path);
        else
        media = new Media(VLCInstance.get(), Uri.parse(path));


        mMediaPlayer.setMedia(media);
        mMediaPlayer.play();
        catch (Exception e)
        Log.e(TAG, e.getMessage());



        @Override
        public void onSurfaceTextureAvailable(SurfaceTexture surface, int width, int height)
        attachViewSurface();

        if (mMediaPlayer.hasMedia())
        mMediaPlayer.play();
        else
        play(mUrl);


        public Bitmap getImage()
        return mTextureView.getBitmap();





        VLCInstance.java:



        import android.content.Context;
        import android.util.Log;

        import org.videolan.libvlc.LibVLC;
        import org.videolan.libvlc.util.VLCUtil;

        public class VLCInstance
        public final static String TAG = "VLC/Util/VLCInstance";

        private static LibVLC sLibVLC = null;

        /** A set of utility functions for the VLC application */
        public synchronized static LibVLC get() throws IllegalStateException
        if (sLibVLC == null)
        final Context context = VLCApplication.getAppContext();
        if(!VLCUtil.hasCompatibleCPU(context))
        Log.e(TAG, VLCUtil.getErrorMsg());
        throw new IllegalStateException("LibVLC initialisation failed: " + VLCUtil.getErrorMsg());


        try
        sLibVLC = new LibVLC(context);
        catch (Throwable e)
        e.printStackTrace();



        return sLibVLC;


        public static synchronized void restart(Context context) throws IllegalStateException
        if (sLibVLC != null)
        sLibVLC.release();
        sLibVLC = new LibVLC(context);








        share|improve this answer












        I'd found a very simple an very fast solution to do this. Just use a TextureView instead of a SurfaceView, and then retrieve the image anytime while playing using the getBitmap() function as shown below.



        public class MainActivity extends AppCompatActivity implements TextureView.SurfaceTextureListener,
        org.videolan.libvlc.media.MediaPlayer.OnBufferingUpdateListener,
        org.videolan.libvlc.media.MediaPlayer.OnCompletionListener,
        org.videolan.libvlc.media.MediaPlayer.OnPreparedListener,
        org.videolan.libvlc.media.MediaPlayer.OnVideoSizeChangedListener

        private AppCompatActivity me = this;
        private MediaPlayer mMediaPlayer;
        private TextureView mTextureViewmTextureView;
        private String mUrl = "/storage/emulated/0/videos/test.mp4";
        private static final String TAG = "MainActivity";

        @Override
        protected void onCreate(Bundle savedInstanceState)
        super.onCreate(savedInstanceState);
        setContentView(R.layout.content_main);

        mMediaPlayer = new MediaPlayer(VLCInstance.get());
        mTextureViewmTextureView = (TextureView) findViewById(R.id.player);
        mTextureView.setSurfaceTextureListener(this);


        private void attachViewSurface()
        final IVLCVout vlcVout = mMediaPlayer.getVLCVout();
        mMediaPlayer.setScale(0);
        vlcVout.detachViews();
        vlcVout.setVideoView(mTextureView);
        vlcVout.setWindowSize(mTextureView.getWidth(), mTextureView.getHeight());
        vlcVout.attachViews();
        mTextureView.setKeepScreenOn(true);



        private void play(String path)
        try
        Media media;
        if (new File(path).exists())
        media = new Media(VLCInstance.get(), path);
        else
        media = new Media(VLCInstance.get(), Uri.parse(path));


        mMediaPlayer.setMedia(media);
        mMediaPlayer.play();
        catch (Exception e)
        Log.e(TAG, e.getMessage());



        @Override
        public void onSurfaceTextureAvailable(SurfaceTexture surface, int width, int height)
        attachViewSurface();

        if (mMediaPlayer.hasMedia())
        mMediaPlayer.play();
        else
        play(mUrl);


        public Bitmap getImage()
        return mTextureView.getBitmap();





        VLCInstance.java:



        import android.content.Context;
        import android.util.Log;

        import org.videolan.libvlc.LibVLC;
        import org.videolan.libvlc.util.VLCUtil;

        public class VLCInstance
        public final static String TAG = "VLC/Util/VLCInstance";

        private static LibVLC sLibVLC = null;

        /** A set of utility functions for the VLC application */
        public synchronized static LibVLC get() throws IllegalStateException
        if (sLibVLC == null)
        final Context context = VLCApplication.getAppContext();
        if(!VLCUtil.hasCompatibleCPU(context))
        Log.e(TAG, VLCUtil.getErrorMsg());
        throw new IllegalStateException("LibVLC initialisation failed: " + VLCUtil.getErrorMsg());


        try
        sLibVLC = new LibVLC(context);
        catch (Throwable e)
        e.printStackTrace();



        return sLibVLC;


        public static synchronized void restart(Context context) throws IllegalStateException
        if (sLibVLC != null)
        sLibVLC.release();
        sLibVLC = new LibVLC(context);









        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 22 '18 at 10:26









        peter bence

        5510




        5510



























            draft saved

            draft discarded
















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.





            Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


            Please pay close attention to the following guidance:


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53238880%2fgetting-current-frame-from-android-vlc-media-player%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            𛂒𛀶,𛀽𛀑𛂀𛃧𛂓𛀙𛃆𛃑𛃷𛂟𛁡𛀢𛀟𛁤𛂽𛁕𛁪𛂟𛂯,𛁞𛂧𛀴𛁄𛁠𛁼𛂿𛀤 𛂘,𛁺𛂾𛃭𛃭𛃵𛀺,𛂣𛃍𛂖𛃶 𛀸𛃀𛂖𛁶𛁏𛁚 𛂢𛂞 𛁰𛂆𛀔,𛁸𛀽𛁓𛃋𛂇𛃧𛀧𛃣𛂐𛃇,𛂂𛃻𛃲𛁬𛃞𛀧𛃃𛀅 𛂭𛁠𛁡𛃇𛀷𛃓𛁥,𛁙𛁘𛁞𛃸𛁸𛃣𛁜,𛂛,𛃿,𛁯𛂘𛂌𛃛𛁱𛃌𛂈𛂇 𛁊𛃲,𛀕𛃴𛀜 𛀶𛂆𛀶𛃟𛂉𛀣,𛂐𛁞𛁾 𛁷𛂑𛁳𛂯𛀬𛃅,𛃶𛁼

            Crossroads (UK TV series)

            ữḛḳṊẴ ẋ,Ẩṙ,ỹḛẪẠứụỿṞṦ,Ṉẍừ,ứ Ị,Ḵ,ṏ ṇỪḎḰṰọửḊ ṾḨḮữẑỶṑỗḮṣṉẃ Ữẩụ,ṓ,ḹẕḪḫỞṿḭ ỒṱṨẁṋṜ ḅẈ ṉ ứṀḱṑỒḵ,ḏ,ḊḖỹẊ Ẻḷổ,ṥ ẔḲẪụḣể Ṱ ḭỏựẶ Ồ Ṩ,ẂḿṡḾồ ỗṗṡịṞẤḵṽẃ ṸḒẄẘ,ủẞẵṦṟầṓế