RenderHeads / UnityPlugin-AVProVideo

AVPro Video is a multi-platform Unity plugin for advanced video playback
https://www.renderheads.com/products/avpro-video/
235 stars 28 forks source link

Has the method of handling the Rewind function been modified on Android? #571

Closed noristaff closed 3 years ago

noristaff commented 3 years ago

After upgrade MediaPlayer.Rewind() function does not work on Android device. Works well in Unity Editor mode and on Windows App.

Your Setup (please complete the following information):

Ste-RH commented 3 years ago

I have just tested rewind here (a simple script to call Rewind() every 4 seconds) and it appears to work as one would expect.

Can you provide some more information? Or maybe send an example project demonstrating the problem to unitysupport@renderheads.com

noristaff commented 3 years ago

Thanks for your comment. In case it may be useful to others as well, I will briefly write a part of the function here.

private void Start() { mediaPlayer.Events.AddListener(OnMediaPlayerEvent); ...

private void OnMediaPlayerEvent(MediaPlayer mp, MediaPlayerEvent.EventType et, ErrorCode errorCode) { switch (et) { case MediaPlayerEvent.EventType.FinishedPlaying: mp.Control.Stop(); // Resolved!!!. It works well mp.Control.Rewind(); mp.Control.Play();

    //mp.Control.Rewind();  // But, This does not work in the case of Android App.
            ...

As you can see, it has been resolved and works well in Android App. However, if there is anything that I am misunderstanding, I would appreciate it if you let me know.

Thank you.

Ste-RH commented 3 years ago

I am a bit lost as to what the actual issue is here?

I set up the demo scene to rewind on the finished event, like this:

image

I disabled the looping flag on the MediaPlayer component.

The video plays back, and when it reaches the end it rewinds and pauses on the first frame.

Adding the play call just makes it essentially looping.

Can you provide some more detailed information of what you are trying to achieve, and how it does not work please? Also, what Android device are you using?

noristaff commented 3 years ago

Thanks for your comment.

What i am trying to achieve. I want to play a specific video file repeatedly only as many times as I want. For example, I want to play a video file only 3 times.

My problem is...(Only android device) ... private void OnMediaPlayerEvent(MediaPlayer mp, MediaPlayerEvent.EventType et, ErrorCode errorCode) { switch(et) { case MediaPlayerEvent.EventType.FinishedPlaying: { if (++repeatCount >= 3) { mp.Control.Stop() repeatCount = 0; ... ... } else { // I expected it to work with the one line below, but this only fails on Android devices (stopped at the last scene).
// mp.Control.Rewind();

// So, substituting the 3 lines below, it works well for all apps including Android devices.
mp.Control.Stop(); mp.Control.Rewind(); mp.Control.Play(); ... ...

        }

My android device is Samsung Galaxy S8 (SM-G950N) / Android 9(PIE)

Video file info. General Format : mp4 Streams : Video(1) Audio(0), Extra(0) Support High-speed mode : Possible Seekable : Possible File size : 288.9KB Duration : 00:00:02.00 Overall bit rate : 1.2 Mbps Writing application : Lavf57.30.100

Video
Codec                       : H264(0x31637661)
H264 Profile                : High@3.1
Size                        : 1024x512
Display aspect ratio        : 2:1
Frame rate                  : 30.0 fps
Decoding                    : Possible
Encoding                    : Possible
Bit rate                    : 1.2 Mbps
B-Frame count               : 2
Duration                    : 00:00:02.00
Start time                  : 00:00:00.00
Has index entry             : Yes
Ste-RH commented 3 years ago

Ahh, yes, I see now.

Yes, there was a small functional change. In v2 we cleared the 'start when ready' flag on a none-looping video finishing. So on a rewind call after a video has finished the video now won't continue to play. Hence the requirement of the 'Play()' call you have added on the finished event. What doesn't make sense is the 'Stop()' you added. What does it do without the this? I have tested here without the stop and things behave as I would expect.

noristaff commented 3 years ago

Thanks for your comment.

// So, substituting the 3 lines below, it works well for all apps including Android devices. // mp.Control.Stop(); // <= Yes, that's right. Even without this line, it works fine. mp.Control.Rewind(); mp.Control.Play();

Yes. I understand what happened. Thank you for a detailed description.