Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cant use player.attach for playing the next video while creating the functionality for playing the next video #6550

Closed
shubhankarMitra opened this issue May 7, 2024 · 4 comments
Labels
type: question A question from the community

Comments

@shubhankarMitra
Copy link

Have you read the Tutorials?
yes

Have you read the FAQ and checked for duplicate open issues?
yes

If the question is related to FairPlay, have you read the tutorial?

yes

What version of Shaka Player are you using?
4.7.12

What browser and OS are you using?
Ubuntu - Chrome and Firefox

Please ask your question

`function Shaka({ videoData, getNextEpisodeId = () => {} }) {
const videRef = useRef(null);
const [player, setPlayer] = useState(null);

async function init(videoData) {
    const player = new Shaka.player();
    await player.attach(videoRef.current); //Stops execution here in the second initialization for the next episode
    setPlayer(player);
    //await player.load(videoData.src)
}

useEffect(() => {
    //Player initialization code
    init(videoData);
}, []);

const handleNext = () => {
    if (player) {
        player.destroy();
    }

    getNextEpisodeId().then((data) => init(data));
};
return (
    <div>
        <video ref={videoRef} autoplay />
        <button onClick={handleNext}>Skip Next</button>
    </div>
);

}`

I have written the code for playing next episode.
The player. attach method does not work the second time i am loading it for the get next episode ,it reachs till there and it stops execution when I am trying to load the second time

@shubhankarMitra shubhankarMitra added the type: question A question from the community label May 7, 2024
@avelad
Copy link
Collaborator

avelad commented May 8, 2024

player.destroy() is a method that returns a promise, you have to wait with await before creating a new player and calling attach.

@avelad avelad added the status: waiting on response Waiting on a response from the reporter(s) of the issue label May 8, 2024
@shubhankarMitra
Copy link
Author

okay , i somewhat solved it using await.
but i want to know is this the right way to play the mext episode or there is a better way?

@shaka-bot shaka-bot removed the status: waiting on response Waiting on a response from the reporter(s) of the issue label May 10, 2024
@avelad
Copy link
Collaborator

avelad commented May 10, 2024

Your solution is optimal.

@avelad avelad added the status: waiting on response Waiting on a response from the reporter(s) of the issue label May 10, 2024
@shaka-bot
Copy link
Collaborator

Closing due to inactivity. If this is still an issue for you or if you have further questions, the OP can ask shaka-bot to reopen it by including @shaka-bot reopen in a comment.

@shaka-bot shaka-bot removed the status: waiting on response Waiting on a response from the reporter(s) of the issue label May 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: question A question from the community
Projects
None yet
Development

No branches or pull requests

3 participants