multiview on same activity using vlc

VLC for Android and Chrome OS specific usage questions
tulkas85
Blank Cone
Blank Cone
Posts: 19
Joined: 07 Aug 2009 13:27

multiview on same activity using vlc

Postby tulkas85 » 27 Feb 2014 16:07

I would know if is possible to use two surface in same layout and view each at same time. In future I would a grid-view of videoview, but each videoview using vlc.

I modify this sample (https://bitbucket.org/edwardcw/libvlc-a ... ?at=master) usign fragment.

The result is that I see only one video...How can I solve ?

this is my code

Code: Select all

package com.compdigitec.libvlcandroidsample; import java.lang.ref.WeakReference; import org.videolan.libvlc.EventHandler; import org.videolan.libvlc.IVideoPlayer; import org.videolan.libvlc.LibVLC; import org.videolan.libvlc.Media; import org.videolan.libvlc.MediaList; import android.app.Activity; import android.content.Intent; import android.content.res.Configuration; import android.graphics.PixelFormat; import android.os.Bundle; import android.os.Handler; import android.os.Message; import android.support.v4.app.Fragment; import android.support.v4.app.FragmentActivity; import android.util.Log; import android.view.Gravity; import android.view.LayoutInflater; import android.view.SurfaceHolder; import android.view.SurfaceView; import android.view.View; import android.view.ViewGroup; import android.view.ViewGroup.LayoutParams; import android.widget.Toast; public class MultipleVideoPlayFragmentActivity extends FragmentActivity { public final static String LOCATION = "com.compdigitec.libvlcandroidsample.MultipleVideoPlayFragmentActivity.location"; private static final String TAG = "MediaPlayer"; public String mFilePatha; @Override public void onCreate(Bundle icicle) { super.onCreate(icicle); setContentView(R.layout.activity_multiple_video_play_fragment); Intent intent = getIntent(); mFilePatha = intent.getExtras().getString(LOCATION); } public static class VideoFragment extends Fragment implements SurfaceHolder.Callback, IVideoPlayer { public final static String TAG = "LibVLCAndroidSample/VideoActivity"; public final static String LOCATION = "com.compdigitec.libvlcandroidsample.VideoFragment.location"; private String mFilePath; // display surface private SurfaceView mSurface; private SurfaceHolder holder; // media player private LibVLC libvlc; private int mVideoWidth; private int mVideoHeight; private final static int VideoSizeChanged = -1; /************* * Activity *************/ @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { return inflater.inflate(R.layout.sample, container, false); } @Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); // Receive path to play from intent Log.d(TAG, "Playing back " + mFilePath); mFilePath=((MultipleVideoPlayFragmentActivity)getActivity()).mFilePatha; // mFilePath="rtsp://192.168.4.125:554/0"; // mFilePath="android.resource://it.nexera.visiamobile/raw/sample_mpeg4"; mSurface = (SurfaceView) getView().findViewById(R.id.surface); holder = mSurface.getHolder(); holder.addCallback(this); } @Override public void onConfigurationChanged(Configuration newConfig) { super.onConfigurationChanged(newConfig); setSize(mVideoWidth, mVideoHeight); } @Override public void onResume() { super.onResume(); createPlayer(mFilePath); } @Override public void onPause() { super.onPause(); releasePlayer(); } @Override public void onDestroy() { super.onDestroy(); releasePlayer(); } /************* * Surface *************/ public void surfaceCreated(SurfaceHolder holder) { } public void surfaceChanged(SurfaceHolder surfaceholder, int format, int width, int height) { if (libvlc != null) libvlc.attachSurface(holder.getSurface(), this); } public void surfaceDestroyed(SurfaceHolder surfaceholder) { } private void setSize(int width, int height) { mVideoWidth = width; mVideoHeight = height; if (mVideoWidth * mVideoHeight <= 1) return; // get screen size int w = getActivity().getWindow().getDecorView().getWidth(); int h = getActivity().getWindow().getDecorView().getHeight(); // getWindow().getDecorView() doesn't always take orientation into // account, we have to correct the values boolean isPortrait = getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT; if (w > h && isPortrait || w < h && !isPortrait) { int i = w; w = h; h = i; } float videoAR = (float) mVideoWidth / (float) mVideoHeight; float screenAR = (float) w / (float) h; if (screenAR < videoAR) h = (int) (w / videoAR); else w = (int) (h * videoAR); // force surface buffer size holder.setFixedSize(mVideoWidth, mVideoHeight); // set display size LayoutParams lp = mSurface.getLayoutParams(); lp.width = w; lp.height = h; mSurface.setLayoutParams(lp); mSurface.invalidate(); } @Override public void setSurfaceSize(int width, int height, int visible_width, int visible_height, int sar_num, int sar_den) { Message msg = Message.obtain(mHandler, VideoSizeChanged, width, height); msg.sendToTarget(); } /************* * Player *************/ private void createPlayer(String media) { releasePlayer(); try { if (media.length() > 0) { Toast toast = Toast.makeText(this.getActivity(), media, Toast.LENGTH_LONG); toast.setGravity(Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL, 0, 0); toast.show(); } // Create a new media player libvlc = LibVLC.getInstance(); libvlc.setHardwareAcceleration(LibVLC.HW_ACCELERATION_DISABLED); libvlc.setSubtitlesEncoding(""); libvlc.setAout(LibVLC.AOUT_OPENSLES); libvlc.setTimeStretching(true); libvlc.setChroma("RV32"); libvlc.setVerboseMode(true); //LibVLC.restart(this.getActivity()); EventHandler.getInstance().addHandler(mHandler); holder.setFormat(PixelFormat.RGBX_8888); holder.setKeepScreenOn(true); MediaList list = libvlc.getMediaList(); list.clear(); list.add(new Media(libvlc, LibVLC.PathToURI(media)), false); libvlc.playIndex(0); } catch (Exception e) { Toast.makeText(this.getActivity(), "Error creating player!", Toast.LENGTH_LONG).show(); } } private void releasePlayer() { if (libvlc == null) return; EventHandler.getInstance().removeHandler(mHandler); libvlc.stop(); libvlc.detachSurface(); holder = null; libvlc.closeAout(); libvlc.destroy(); libvlc = null; mVideoWidth = 0; mVideoHeight = 0; } /************* * Events *************/ private Handler mHandler = new MyHandler(this); private static class MyHandler extends Handler { private WeakReference<VideoFragment> mOwner; public MyHandler(VideoFragment owner) { mOwner = new WeakReference<VideoFragment>(owner); } @Override public void handleMessage(Message msg) { VideoFragment player = mOwner.get(); // SamplePlayer events if (msg.what == VideoSizeChanged) { player.setSize(msg.arg1, msg.arg2); return; } // Libvlc events Bundle b = msg.getData(); switch (b.getInt("event")) { case EventHandler.MediaPlayerEndReached: player.releasePlayer(); break; case EventHandler.MediaPlayerPlaying: case EventHandler.MediaPlayerPaused: case EventHandler.MediaPlayerStopped: default: break; } } } } }

this is my layout

Code: Select all

<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <fragment class="com.compdigitec.libvlcandroidsample.MultipleVideoPlayFragmentActivity$VideoFragment" android:id="@+id/video_1_fragment" android:layout_width="100dp" android:layout_height="0dp" android:layout_weight="1" /> <fragment class="com.compdigitec.libvlcandroidsample.MultipleVideoPlayFragmentActivity$VideoFragment" android:id="@+id/video_2_fragment" android:layout_width="100dp" android:layout_height="0dp" android:layout_weight="1" /> </LinearLayout>
this is single fragment layout

Code: Select all

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:baselineAligned="false" android:orientation="vertical" tools:context=".SampleActivity" > <FrameLayout android:layout_width="match_parent" android:layout_height="match_parent" > <SurfaceView android:id="@+id/surface" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_gravity="center" /> </FrameLayout>

EDIT:
From logcat I not see important error, but I think that there are rendering problems for android UIThread

edwardw
Big Cone-huna
Big Cone-huna
Posts: 2346
Joined: 24 Jun 2012 23:36
VLC version: 3.0.0-git

Re: multiview on same activity using vlc

Postby edwardw » 28 Feb 2014 21:54

The thing is, right now with our architecture, we can have only one thing playing with one libVLC instance. We're working on this, but your best bet in the meanwhile is to spawn some multiple libVLC instances and use the setSurface for each.

tulkas85
Blank Cone
Blank Cone
Posts: 19
Joined: 07 Aug 2009 13:27

Re: multiview on same activity using vlc

Postby tulkas85 » 03 Mar 2014 09:47

I thought that by calling the library twice with LibVLC.getInstance() I got two different instances, instead using the debug I can see that in fact the instance is the same.

how can I get two different instances of the library?

edwardw
Big Cone-huna
Big Cone-huna
Posts: 2346
Joined: 24 Jun 2012 23:36
VLC version: 3.0.0-git

Re: multiview on same activity using vlc

Postby edwardw » 03 Mar 2014 21:18

That's a good point I missed first time round. I guess there is no good way to do it right now, per se.

Sorry about that; we'll continue to work on refactoring libVLC to become more modular.

tulkas85
Blank Cone
Blank Cone
Posts: 19
Joined: 07 Aug 2009 13:27

Re: multiview on same activity using vlc

Postby tulkas85 » 21 Oct 2014 17:09

some news for multiple instances of vlc ?


Return to “VLC for Android and Chrome OS”

Who is online

Users browsing this forum: No registered users and 17 guests