LunatiqueCoder / react-native-media-console

A React Native video player. Built with TypeScript ❤️
MIT License
184 stars 28 forks source link

onEnd callback doesnt trigger when rewind #60

Closed FightFarewellFearless closed 9 months ago

FightFarewellFearless commented 1 year ago

Hey, I think I just found a bug.

For example, if the current duration is 2:50, the video duration is 3:00, and the rewind time is 15 seconds, when you rewind forward at 2:50, the video should end, right? Because it has reached the limit, but it's not. Somehow, it just plays back to 0:00 and doesn't trigger the onEnd callback

LunatiqueCoder commented 1 year ago

Hello @FightFarewellFearless.

Thanks for trying out the library and opening an issue. I'll look into it this weekend or the next. It will be a lot faster if you can provide a reproduction code. Thank you!

FightFarewellFearless commented 1 year ago

Hello @FightFarewellFearless.

Thanks for trying out the library and opening an issue. I'll look into it this weekend or the next. It will be a lot faster if you can provide a reproduction code. Thank you!

Sure. This is my video component

              <Videos
                key={
                  this.state.data.streamingLink[this.state.part].sources[0].src
                }
                showOnEnd={true}
                title={this.state.data.title}
                disableBack={!this.state.fullscreen}
                onBack={this.onBack}
                toggleResizeModeOnFullscreen={false}
                isFullscreen={this.state.fullscreen}
                onEnterFullscreen={this.enterFullscreen.bind(this)}
                onExitFullscreen={this.exitFullscreen.bind(this)}
                source={{
                  uri: this.state.data.streamingLink[this.state.part].sources[0]
                    .src,
                }}
                onEnd={this.onEnd}
                rewindTime={10}
                showDuration={true}
              />

And this is my onEnd function

  onEnd = () => {
    if (this.state.part < this.state.data.streamingLink.length - 1) {
      this.setState({
        part: this.state.part + 1,
      });
    }

So its like going to the next video automatically when the video is end

LunatiqueCoder commented 1 year ago

@FightFarewellFearless Might not be relevant but - what version of React are you using?

Did you also add a console.log inside the onEnd function to check it? E.g:

  onEnd = () => {
    console.log('onEnd called'); // <----------------- Add this line here

    if (this.state.part < this.state.data.streamingLink.length - 1) {
      this.setState({
        part: this.state.part + 1,
      });
    }
FightFarewellFearless commented 1 year ago

@criszz77 yes, i mean its working fine if i didnt rewind forward, and if i rewind forward and the rewind time larger than the remaining duration, it just replay the video and doesnt trigger the onend function.

And im using react version 18.2.0 and react native version 0.71.1

LunatiqueCoder commented 1 year ago

Why are you still using class components? They are legacy in React. Nowadays functional components are used along with hooks.

LunatiqueCoder commented 1 year ago

Perhaps I will need more code to get it running. Like your state.

FightFarewellFearless commented 1 year ago

Oh, yea, I'm more comfortable using class component.

LunatiqueCoder commented 1 year ago

Well I strongly suggest you to get comfortable using hooks. They will make your life much easier.

FightFarewellFearless commented 1 year ago

Perhaps I will need more code to get it running. Like your state.

You can check the full code here if you want https://github.com/FightFarewellFearless/anime-react-native/blob/master/src/Video.js

LunatiqueCoder commented 1 year ago

Having an understanding of how class components work is also very good to know, but they you have to write a lot of code to actually do something, and thus it’s easier to introduce bugs

FightFarewellFearless commented 1 year ago

Well I strongly suggest you to get comfortable using hooks. They will make your life much easier.

Thanks, i will move soon ig

FightFarewellFearless commented 1 year ago

@criszz77 ah, also i want to request new feature. Can you add like "try again" if the video is error

LunatiqueCoder commented 1 year ago

There is an ongoing issue for this here: https://github.com/criszz77/react-native-media-console/issues/23

Unfortunately, I'm quite busy with my other open source project for the moment, but I'll try to get this module improved ASAP.

FightFarewellFearless commented 1 year ago

Any update?

FightFarewellFearless commented 1 year ago

https://github.com/LunatiqueCoder/react-native-media-console/pull/58

I think this pull request will fix it

LunatiqueCoder commented 9 months ago

Not reproducible. Check #58, maybe you will find a solution there.