Git Product home page Git Product logo

frame-video-view's Introduction

frame-viedo-view

Have you got any display issues using VideoView?
I had too. I wrote a blog post where you can find more details about these issues and how I solved them.

How it works?

FrameVideoView solves flickering and black screen issues by showing placeholder on the proper time.
Placeholder is a simple View on top of the VideoView. Placeholder is visisble just after onPause is called and invisible when onResume is called.
It allows to hide VideoView during screen transitions which causes strange issues. If your device is running API level 14 or higher it will use TextureView to increase video playback performance, otherwise VideoView will be used.

How to use it?

Step 1. Add it in your root build.gradle at the end of repositories:

	allprojects {
		repositories {
			...
			maven { url "https://jitpack.io" }
		}
	}

Step 2. Add the dependency:

	dependencies {
	        compile 'com.github.mklimek:frame-video-view:$RELEASE_VERSION'
	}

Current $RELEASE_VERSION is

Step 3. Add view in xml:

<com.mklimek.frameviedoview.FrameVideoView
    android:id="@+id/frame_video_view"
    android:layout_width="@dimen/video_width"
    android:layout_height="@dimen/video_height"
  />

Step 4. Setup resource and FrameVideoViewListener:

frameVideoView = (FrameVideoView) findViewById(R.id.frameVideoView);
frameVideoView.setup(Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.fb));
frameVideoView.setFrameVideoViewListener(new FrameVideoViewListener() {
      @Override
      public void mediaPlayerPrepared(MediaPlayer mediaPlayer) {
          mediaPlayer.start();
      }
      
      @Override
      void mediaPlayerPrepareFailed(MediaPlayer mediaPlayer, String error){
      }
});

you can call pause, resume, looping and other methods available in MediaPlayer.

See example for more details.

frame-video-view's People

Contributors

alouanemed avatar m-kubis avatar mklimek avatar sharpmobilecode avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

frame-video-view's Issues

compile 'com.github.mklimek:frame-video-view:1.3.1' not working

Hi!
You said to get the release code from the releases tab, and last one is 1.3.1. When trying to add the line

compile 'com.github.mklimek:frame-video-view:1.3.1'

I get

Error:(32, 13) Failed to resolve: com.github.mklimek:frame-video-view:v1.3.1

Any ideas? Thanks!

black screen

when first into view, will see black screen flash. if you goto another activity,then back, also see black screen flash.

Release on texture surface destroyed

Hi, there is a re-initialization issue on surface destruction. For example when placing the video into the RecyclerView. The recycling of the view can be handled with #onResume()/#onPause() with the RecycleView#onBindViewHolder(...)/#onViewRecycled(...) callbacks. However the surface state change callbacks of the implementation are not accessible from the outside. The exact moment the texture view goes out of view (the last pixel scrolls out of the screen), TextureViewImpl#onSurfaceTextureDestroyed(Surface) gets called and the following onSurfaceTextureAvailable(Surface) doesn't initialize the media player due to not being released (and flag set).

The player should be released and the placeholder view shown. Simple doing #onResume() in TextureViewImpl#onSurfaceTextureDestroyed(Surface) should do the trick.
Before
After releasing on surface destruction

nexus5

when I use your demo,the video never show
I have debugged,and found the method onSurfaceTextureAvailable is not called,but I don't know why
can you fix this?

Using wrap_content on FrameVideoView

I've used FrameVideoView in my application but I'm having difficulty getting it to scale on different screen sizes.
With the stock VideoView class I set layout_height = wrap_content, however, if I do this with FrameVideoView it fills the entire screen.

Do you have any idea advice as to how I could get FrameVideoView to resize to the content so as to preserve the aspect ratio on different screen sizes?

Below is my implementation of the respective views. They sit inside a RelativeLayout, hence the layout_gravity.

        <FrameVideoView
            android:id="@+id/photo_instruction_video_view"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="center_horizontal|top"
        </FrameVideoView>
        <VideoView
            android:id="@+id/photo_instruction_video_view"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="center_horizontal|top"/>

Love the library, slick solution to the flickering problem.

TextureViewImpl.removeVideo throws NullPointerException

NullPointerException is thrown while destroying the resources. The problem happens if frameVideoView.setup is not called (when the videoView is not used).

In this method placeholderView is null and it causes the problem.

private void removeVideo() {
        this.placeholderView.setVisibility(0);
        this.release();
}

E/AndroidRuntime: FATAL EXCEPTION: main
Process: my.app.android, PID: 30161
java.lang.NullPointerException: Attempt to invoke virtual method 'void android.view.View.setVisibility(int)' on a null object reference
at com.mklimek.frameviedoview.TextureViewImpl.removeVideo(TextureViewImpl.java:147)
at com.mklimek.frameviedoview.TextureViewImpl.onSurfaceTextureDestroyed(TextureViewImpl.java:103)
at android.view.TextureView.destroySurface(TextureView.java:237)
at android.view.TextureView.destroyHardwareResources(TextureView.java:340)
at android.view.ThreadedRenderer.destroyResources(ThreadedRenderer.java:216)
at android.view.ThreadedRenderer.destroyResources(ThreadedRenderer.java:223)
at android.view.ThreadedRenderer.destroyResources(ThreadedRenderer.java:223)
at android.view.ThreadedRenderer.destroyResources(ThreadedRenderer.java:223)
at android.view.ThreadedRenderer.destroyResources(ThreadedRenderer.java:223)
at android.view.ThreadedRenderer.destroyResources(ThreadedRenderer.java:223)
at android.view.ThreadedRenderer.destroyResources(ThreadedRenderer.java:223)
at android.view.ThreadedRenderer.destroyResources(ThreadedRenderer.java:223)
at android.view.ThreadedRenderer.destroyResources(ThreadedRenderer.java:223)
at android.view.ThreadedRenderer.destroyResources(ThreadedRenderer.java:223)
at android.view.ThreadedRenderer.destroyResources(ThreadedRenderer.java:223)
at android.view.ThreadedRenderer.destroyResources(ThreadedRenderer.java:223)
at android.view.ThreadedRenderer.destroyResources(ThreadedRenderer.java:223)
at android.view.ThreadedRenderer.destroyResources(ThreadedRenderer.java:223)
at android.view.ThreadedRenderer.destroyHardwareResources(ThreadedRenderer.java:211)
at android.view.ViewRootImpl.destroyHardwareResources(ViewRootImpl.java:965)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1802)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1487)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:7450)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:920)
at android.view.Choreographer.doCallbacks(Choreographer.java:695)
at android.view.Choreographer.doFrame(Choreographer.java:631)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:906)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:158)
at android.app.ActivityThread.main(ActivityThread.java:7229)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)

NoClassDefFoundError

java.lang.NoClassDefFoundError: org.slf4j.LoggerFactory
at mateuszklimek.framevideoview.FrameVideoView.(FrameVideoView.java:26)
at com.papelook.favor.view.advertise.VideoAdvertise.init(VideoAdvertise.java:62)
at com.papelook.favor.view.advertise.VideoAdvertise.setAdvertise(VideoAdvertise.java:96)
at com.papelook.favor.ui.fragment.WriterArticleListFragment$GetAdvertiseTask.onPostExecute(WriterArticleListFragment.java:396)
at com.papelook.favor.ui.fragment.WriterArticleListFragment$GetAdvertiseTask.onPostExecute(WriterArticleListFragment.java:321)
at android.os.AsyncTask.finish(AsyncTask.java:632)
at android.os.AsyncTask.access$600(AsyncTask.java:177)
at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:645)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:157)
at android.app.ActivityThread.main(ActivityThread.java:5356)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1265)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1081)
at dalvik.system.NativeStart.main(Native Method)

On Video Complete Listner

Hello Team,
I am having the problem for which this project was created, it solve my problem of black area display. But there are some tasks that must start after the video is finished (short video between 1-3 seconds, how to achieve this?
I tried adding :

            public void mediaPlayerPrepared(final MediaPlayer mediaPlayer) {
                mediaPlayer.start();
                mediaPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {

But this makes my code in halted, no error/exception but video also not playing.

Video Does Not Play When Using Drawable As Place Holder

When you use a drawable as a place holder, the video does not play and only shows the place holder.

Example:

frameVideoView.setup(videoUri, ContextCompat.getDrawable(this, R.drawable.my_drawable_place_holder))

If you set a color as a place holder, the video plays.

IllegalStateException when removing FrameVideoView from the layout

I have a chat where I use FrameVideoView to animate the writing state of the chat bubble (three dots moving up and down). When I remove the FrameVideoView to replace it with the static text chat bubble, an IllegalStateException is thrown. Before I remove the FrameVideoView, I check that the mediaPlayer = null but when it comes toTextureViewImpl.release(), the MediaPlayer is not null and the exception is thrown.

Stack trace is the following:

    java.lang.IllegalStateException
        at android.media.MediaPlayer._stop(Native Method)
        at android.media.MediaPlayer.stop(MediaPlayer.java:1231)
        at com.mklimek.frameviedoview.TextureViewImpl.release(TextureViewImpl.java:138)
        at com.mklimek.frameviedoview.TextureViewImpl.removeVideo(TextureViewImpl.java:150)
        at com.mklimek.frameviedoview.TextureViewImpl.onSurfaceTextureDestroyed(TextureViewImpl.java:103)
        at android.view.TextureView.destroySurface(TextureView.java:237)
        at android.view.TextureView.onDetachedFromWindowInternal(TextureView.java:227)
        at android.view.View.dispatchDetachedFromWindow(View.java:14556)
        at android.view.ViewGroup.dispatchDetachedFromWindow(ViewGroup.java:3063)
        at android.view.ViewGroup.dispatchDetachedFromWindow(ViewGroup.java:3063)
        at android.view.ViewGroup.removeViewInternal(ViewGroup.java:4603)
        at android.view.ViewGroup.removeViewInternal(ViewGroup.java:4576)
        at android.view.ViewGroup.removeView(ViewGroup.java:4507)
        at xxxx.welcome.fragment.NonOnboardingPostAuthFragment$1.onAnimationStart(NonOnboardingPostAuthFragment.java:65)
        at android.view.animation.Animation$1.run(Animation.java:362)
        at android.os.Handler.handleCallback(Handler.java:739)
        at android.os.Handler.dispatchMessage(Handler.java:95)
        at android.os.Looper.loop(Looper.java:148)
        at android.app.ActivityThread.main(ActivityThread.java:5417)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)

Any suggestions how to make it work?
PS: it worked six months ago.

Can we play Video from server URL

Hi,

I want to play video from server url, i am trying to replace local path to server url but cant play video and throwing exception, if you know then help me.

Thanx

Get Frames from FrameVideoView

Hello, i want to get the frames from the FrameVideoView object to save as an image. Have any way to do this?

public void startStream() {
        String mediaUrl = "rtsp://192.168.1.18:554/h264/ch0/main/av_stream";

        mFrameVideoView.setup(Uri.parse(mediaUrl));
        mFrameVideoView.setFrameVideoViewListener(new FrameVideoViewListener() {
            @Override
            public void mediaPlayerPrepared(MediaPlayer mediaPlayer) {
                mediaPlayer.start();
            }

            @Override
            public void mediaPlayerPrepareFailed(MediaPlayer mediaPlayer, String error){
            }
        });
    }

Can't turn off looping?

Thanks for making this library available - I've been trying to use it but am running into an issue because of the ordering in TextureViewImpl.java's onPrepared() function.

In it, you execute the callback listener.mediaPlayerPrepared(), which is where I set mediaPlayer.setLooping(false). However, after returning from the call back, you explicitly call setLooping(true). There doesn't seem to be another chance for me to call setLooping before the video starts playing.

Any thoughts on how to get around this, am I missing something, or is this a bug?

Thanks!

Support using custom Drawable as placeholder

I think it would be nice if there was an additional overload of setup() that accepted a Drawable to use as a placeholder background, as an alternative (or in addition) to the background color that's already supported.

In my particular situation, I always know what the first frame of my videos will look like ahead of time, so it could be used to provide a more seamless transition once the video starts playing.

FrameVideoViewListener must either be declared abstract or implement abstract method

I'm trying to load a video using your library from within a ViewPager fragment. I'm pretty much following the same on the readme but I'm getting the error mentioned above while doing:

FrameVideoView frameVideoView = (FrameVideoView) fragment.findViewById(R.id.frame_video_view);
            frameVideoView.setup(Uri.parse("android.resource://" + getActivity().getPackageName() + "/" + R.raw.playlist_2_video_1));
            frameVideoView.setFrameVideoViewListener(new FrameVideoViewListener() {
                @Override
                public void mediaPlayerPrepared(final MediaPlayer mediaPlayer) {
                    mediaPlayer.start();
                }
            });

This is just for testing, what I really want to be able to do is save a reference of mediaPlayer or something, so I can call mediaPlayer.start() when my fragment is visible to the user on a different method, but that's on me.

Video URI needs to be provided on initialization

If the video URI is set after a delay or on a user action rather than right after initialization, the surface texture gets ready and an exception is thrown in TextureViewImpl.prepare(). It is handled, but the video cannot be run any more, no callbacks.

04-07 16:43:48.859 22584-22584/? E/TextureViewImpl: cannot prepare media player with SurfaceTexture java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String android.net.Uri.getScheme()' on a null object reference at android.media.MediaPlayer.setDataSource(MediaPlayer.java:985) at android.media.MediaPlayer.setDataSource(MediaPlayer.java:968) at com.mklimek.frameviedoview.TextureViewImpl.prepare(TextureViewImpl.java:72) at com.mklimek.frameviedoview.TextureViewImpl.onSurfaceTextureAvailable(TextureViewImpl.java:66) at android.view.TextureView.getHardwareLayer(TextureView.java:368) at android.view.View.updateDisplayListIfDirty(View.java:15157) at android.view.View.draw(View.java:15954) at android.view.ViewGroup.drawChild(ViewGroup.java:3609) at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3399) at android.view.View.updateDisplayListIfDirty(View.java:15175) at android.view.View.draw(View.java:15954) at android.view.ViewGroup.drawChild(ViewGroup.java:3609) at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3399) at android.view.View.updateDisplayListIfDirty(View.java:15175) at android.view.View.draw(View.java:15954) at android.view.ViewGroup.drawChild(ViewGroup.java:3609) at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3399) at android.view.View.updateDisplayListIfDirty(View.java:15175) at android.view.View.draw(View.java:15954) at android.view.ViewGroup.drawChild(ViewGroup.java:3609) at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3399) at android.view.View.updateDisplayListIfDirty(View.java:15175) at android.view.View.draw(View.java:15954) at android.view.ViewGroup.drawChild(ViewGroup.java:3609) at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3399) at android.view.View.draw(View.java:16187) at com.android.internal.policy.PhoneWindow$DecorView.draw(PhoneWindow.java:2690) at android.view.View.updateDisplayListIfDirty(View.java:15180) at android.view.ThreadedRenderer.updateViewTreeDisplayList(ThreadedRenderer.java:281) at android.view.ThreadedRenderer.updateRootDisplayList(ThreadedRenderer.java:287) at android.view.ThreadedRenderer.draw(ThreadedRenderer.java:322) at android.view.ViewRootImpl.draw(ViewRootImpl.java:2615) at android.view.ViewRootImpl.performDraw(ViewRootImpl.java:2434) at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2067) at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1107) at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6013) at android.view.Choreographer$CallbackRecord.run(Choreographer.java:858) at android.view.Choreographer.doCallbacks(Choreographer.java:670) at android.view.Choreographer.doFrame(Choreographer.java:606) at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:844) at android.os.Handler.handleCallback(Handler.java:739) at android.os.Handler.dispatchMessage(Handler.java:95) at android.os.Looper.loop(Looper.java:148) at android.app.ActivityThread.main(ActivityThread.java:5417) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)

If you have trouble reproducing, I can provide a code.
[email protected]

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.