Page 1 of 1

to test vlc found problems

Posted: 19 May 2014 10:33
by myplxdm
The left and right under the angle of the screen with the green block
Image

Code: Select all

public class MainActivity extends Activity implements IVideoPlayer { public final static String TAG = "MainActivity"; private SurfaceView mSurface; private SurfaceView mSubtitlesSurface; private SurfaceHolder mSurfaceHolder; private SurfaceHolder mSubtitlesSurfaceHolder; private LibVLC mLibVLC; private int mUiVisibility = -1; // private int mVideoHeight; private int mVideoWidth; private int mVideoVisibleHeight; private int mVideoVisibleWidth; private int mSarNum; private int mSarDen; private int mScreenOrientation; // private static final int OVERLAY_TIMEOUT = 4000; private static final int OVERLAY_INFINITE = 3600000; private static final int FADE_OUT = 1; private static final int SHOW_PROGRESS = 2; private static final int SURFACE_SIZE = 3; private static final int AUDIO_SERVICE_CONNECTION_SUCCESS = 5; private static final int AUDIO_SERVICE_CONNECTION_FAILED = 6; private static final int FADE_OUT_INFO = 4; // private static final int SURFACE_BEST_FIT = 0; private static final int SURFACE_FIT_HORIZONTAL = 1; private static final int SURFACE_FIT_VERTICAL = 2; private static final int SURFACE_FILL = 3; private static final int SURFACE_16_9 = 4; private static final int SURFACE_4_3 = 5; private static final int SURFACE_ORIGINAL = 6; private int mCurrentSize = SURFACE_BEST_FIT; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mSurface = (SurfaceView) findViewById(R.id.player_surface); mSurfaceHolder = mSurface.getHolder(); String chroma = ""; if (LibVlcUtil.isGingerbreadOrLater() && chroma.equals("YV12")) { mSurfaceHolder.setFormat(ImageFormat.YV12); } else if (chroma.equals("RV16")) { mSurfaceHolder.setFormat(PixelFormat.RGB_565); } else { mSurfaceHolder.setFormat(PixelFormat.RGBX_8888); } mSurfaceHolder.addCallback(mSurfaceCallback); mSubtitlesSurface = (SurfaceView) findViewById(R.id.subtitles_surface); mSubtitlesSurfaceHolder = mSubtitlesSurface.getHolder(); mSubtitlesSurfaceHolder.setFormat(PixelFormat.RGBA_8888); mSubtitlesSurface.setZOrderMediaOverlay(true); mSubtitlesSurfaceHolder.addCallback(mSubtitlesSurfaceCallback); Button but = (Button) findViewById(R.id.but); but.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View arg0) { mSurface.setKeepScreenOn(true); mLibVLC.playMRL("file:///storage/sdcard0/11.mp4"); } }); if (LibVlcUtil.isICSOrLater()) getWindow() .getDecorView() .findViewById(android.R.id.content) .setOnSystemUiVisibilityChangeListener( new OnSystemUiVisibilityChangeListener() { @Override public void onSystemUiVisibilityChange( int visibility) { if (visibility == mUiVisibility) return; setSurfaceSize(mVideoWidth, mVideoHeight, mVideoVisibleWidth, mVideoVisibleHeight, mSarNum, mSarDen); // if (visibility == // View.SYSTEM_UI_FLAG_VISIBLE && !mShowing // && !isFinishing()) { // showOverlay(); // } mUiVisibility = visibility; } }); try { mLibVLC = getLibVlcInstance(); } catch (LibVlcException e) { Log.d(TAG, "LibVLC initialisation failed"); return; } mScreenOrientation = 4; mLibVLC.eventVideoPlayerActivityCreated(true); setRequestedOrientation(mScreenOrientation != 100 ? mScreenOrientation : getScreenOrientation()); } @Override public void onConfigurationChanged(Configuration newConfig) { setSurfaceSize(mVideoWidth, mVideoHeight, mVideoVisibleWidth, mVideoVisibleHeight, mSarNum, mSarDen); super.onConfigurationChanged(newConfig); } @SuppressWarnings("deprecation") private int getScreenRotation() { WindowManager wm = (WindowManager) getSystemService(Context.WINDOW_SERVICE); Display display = wm.getDefaultDisplay(); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.FROYO /* * Android 2.2 * has * getRotation */) { try { Method m = display.getClass().getDeclaredMethod("getRotation"); return (Integer) m.invoke(display); } catch (Exception e) { return Surface.ROTATION_0; } } else { return display.getOrientation(); } } @TargetApi(Build.VERSION_CODES.GINGERBREAD) private int getScreenOrientation() { WindowManager wm = (WindowManager) getSystemService(Context.WINDOW_SERVICE); Display display = wm.getDefaultDisplay(); int rot = getScreenRotation(); /* * Since getRotation() returns the screen's "natural" orientation, which * is not guaranteed to be SCREEN_ORIENTATION_PORTRAIT, we have to * invert the SCREEN_ORIENTATION value if it is "naturally" landscape. */ @SuppressWarnings("deprecation") boolean defaultWide = display.getWidth() > display.getHeight(); if (rot == Surface.ROTATION_90 || rot == Surface.ROTATION_270) defaultWide = !defaultWide; if (defaultWide) { switch (rot) { case Surface.ROTATION_0: return ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE; case Surface.ROTATION_90: return ActivityInfo.SCREEN_ORIENTATION_PORTRAIT; case Surface.ROTATION_180: // SCREEN_ORIENTATION_REVERSE_PORTRAIT only available since API // Level 9+ return (Build.VERSION.SDK_INT >= Build.VERSION_CODES.FROYO ? ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE : ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); case Surface.ROTATION_270: // SCREEN_ORIENTATION_REVERSE_LANDSCAPE only available since API // Level 9+ return (Build.VERSION.SDK_INT >= Build.VERSION_CODES.FROYO ? ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT : ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); default: return 0; } } else { switch (rot) { case Surface.ROTATION_0: return ActivityInfo.SCREEN_ORIENTATION_PORTRAIT; case Surface.ROTATION_90: return ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE; case Surface.ROTATION_180: // SCREEN_ORIENTATION_REVERSE_PORTRAIT only available since API // Level 9+ return (Build.VERSION.SDK_INT >= Build.VERSION_CODES.FROYO ? ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT : ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); case Surface.ROTATION_270: // SCREEN_ORIENTATION_REVERSE_LANDSCAPE only available since API // Level 9+ return (Build.VERSION.SDK_INT >= Build.VERSION_CODES.FROYO ? ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE : ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); default: return 0; } } } public LibVLC getLibVlcInstance() throws LibVlcException { LibVLC instance = LibVLC.getExistingInstance(); if (instance == null) { instance = LibVLC.getInstance(); final Context context = this; SharedPreferences pref = PreferenceManager .getDefaultSharedPreferences(context); instance.init(context); instance.setOnNativeCrashListener(new LibVLC.OnNativeCrashListener() { @Override public void onNativeCrash() { } }); } return instance; } private final SurfaceHolder.Callback mSurfaceCallback = new Callback() { @Override public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) { if (format == PixelFormat.RGBX_8888) Log.d(TAG, "Pixel format is RGBX_8888"); else if (format == PixelFormat.RGB_565) Log.d(TAG, "Pixel format is RGB_565"); else if (format == ImageFormat.YV12) Log.d(TAG, "Pixel format is YV12"); else Log.d(TAG, "Pixel format is other/unknown"); mLibVLC.attachSurface(holder.getSurface(), MainActivity.this); } @Override public void surfaceCreated(SurfaceHolder holder) { } @Override public void surfaceDestroyed(SurfaceHolder holder) { mLibVLC.detachSurface(); } }; private final SurfaceHolder.Callback mSubtitlesSurfaceCallback = new Callback() { @Override public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) { mLibVLC.attachSubtitlesSurface(holder.getSurface()); } @Override public void surfaceCreated(SurfaceHolder holder) { } @Override public void surfaceDestroyed(SurfaceHolder holder) { mLibVLC.detachSubtitlesSurface(); } }; @Override public void setSurfaceSize(int width, int height, int visible_width, int visible_height, int sar_num, int sar_den) { mVideoHeight = height; mVideoWidth = width; mVideoVisibleHeight = visible_height; mVideoVisibleWidth = visible_width; mSarNum = sar_num; mSarDen = sar_den; Message msg = mHandler.obtainMessage(SURFACE_SIZE); mHandler.sendMessage(msg); } private final Handler mHandler = new VideoPlayerHandler(this); private static class VideoPlayerHandler extends Handler { private WeakReference<MainActivity> mOwner; public VideoPlayerHandler(MainActivity owner) { mOwner = new WeakReference<MainActivity>(owner); } public MainActivity getOwner() { return mOwner.get(); } @Override public void handleMessage(Message msg) { MainActivity activity = getOwner(); if (activity == null) // WeakReference could be GC'ed early return; switch (msg.what) { case FADE_OUT: break; case SHOW_PROGRESS: break; case SURFACE_SIZE: activity.changeSurfaceSize(); break; case FADE_OUT_INFO: // activity.fadeOutInfo(); break; case AUDIO_SERVICE_CONNECTION_SUCCESS: // activity.startPlayback(); break; case AUDIO_SERVICE_CONNECTION_FAILED: activity.finish(); break; } } }; private void changeSurfaceSize() { int sw; int sh; sw = getWindow().getDecorView().getWidth(); sh = getWindow().getDecorView().getHeight(); double dw = sw, dh = sh; boolean isPortrait; // getWindow().getDecorView() doesn't always take orientation into // account, we have to correct the values isPortrait = getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT; if (sw > sh && isPortrait || sw < sh && !isPortrait) { dw = sh; dh = sw; } // sanity check if (dw * dh == 0 || mVideoWidth * mVideoHeight == 0) { Log.e(TAG, "Invalid surface size"); return; } // compute the aspect ratio double ar, vw; if (mSarDen == mSarNum) { /* No indication about the density, assuming 1:1 */ vw = mVideoVisibleWidth; ar = (double) mVideoVisibleWidth / (double) mVideoVisibleHeight; } else { /* Use the specified aspect ratio */ vw = mVideoVisibleWidth * (double) mSarNum / mSarDen; ar = vw / mVideoVisibleHeight; } // compute the display aspect ratio double dar = dw / dh; switch (mCurrentSize) { case SURFACE_BEST_FIT: if (dar < ar) dh = dw / ar; else dw = dh * ar; break; case SURFACE_FIT_HORIZONTAL: dh = dw / ar; break; case SURFACE_FIT_VERTICAL: dw = dh * ar; break; case SURFACE_FILL: break; case SURFACE_16_9: ar = 16.0 / 9.0; if (dar < ar) dh = dw / ar; else dw = dh * ar; break; case SURFACE_4_3: ar = 4.0 / 3.0; if (dar < ar) dh = dw / ar; else dw = dh * ar; break; case SURFACE_ORIGINAL: dh = mVideoVisibleHeight; dw = vw; break; } SurfaceView surface; SurfaceView subtitlesSurface; SurfaceHolder surfaceHolder; SurfaceHolder subtitlesSurfaceHolder; surface = mSurface; subtitlesSurface = mSubtitlesSurface; surfaceHolder = mSurfaceHolder; subtitlesSurfaceHolder = mSubtitlesSurfaceHolder; // force surface buffer size surfaceHolder.setFixedSize(mVideoWidth, mVideoHeight); subtitlesSurfaceHolder.setFixedSize(mVideoWidth, mVideoHeight); // set display size LayoutParams lp = surface.getLayoutParams(); lp.width = (int) Math.ceil(dw * mVideoWidth / mVideoVisibleWidth); lp.height = (int) Math.ceil(dh * mVideoHeight / mVideoVisibleHeight); surface.setLayoutParams(lp); subtitlesSurface.setLayoutParams(lp); surface.invalidate(); subtitlesSurface.invalidate(); } }

Re: to test vlc found problems

Posted: 20 May 2014 07:56
by myplxdm
resolve

Re: to test vlc found problems

Posted: 21 May 2014 18:57
by Jean-Baptiste Kempf
Please share your code fixes.

Re: to test vlc found problems

Posted: 22 May 2014 02:47
by myplxdm
i am sorry, The problem is because my example does not call updateLibVlcSettings

Re: to test vlc found problems

Posted: 24 May 2014 01:53
by edwardw
What exactly is the situation?