Comments (7)
The problem is when you
Each time you navigate it sends in a new prop causing the: componentWillReceiveProps to fire which resets the play list. I am working on a solution. Once I have it I will fork the project and then submit a merge request.
from cassette.
@MichaelLeeHobbs thank you! I'll be happy to look over the PR and merge as long as it makes sense. Sorry for missing your post earlier.
from cassette.
@benwiley4000 I ended up customizing the player. I'm building a podcast website. Originally, I was passing a reference up from the component that holds the player and then back down into any component that would need access to it. This was cumbersome, so I put the player in the global context for now like so and removed the componentWillReceiveProps.
componentWillMount() {
window.Player = {
play: this.play.bind(this),
addToPlayList: this.addToPlayList.bind(this),
clearPlayList: this.clearPlayList.bind(this)
};
}
play(value) {
console.log("AudioPlayer.addToPlayList.value: ", value);
if (!value.url || !value.displayText) {
return;
}
this.playlist = [value];
this.currentTrackIndex = -1;
this.skipToNextTrack(true);
}
addToPlayList(value) {
console.log("AudioPlayer.addToPlayList.value: ", value);
if (!value.url || !value.displayText) {
return;
}
this.playlist.push(value);
}
clearPlayList() {
this.playlist = [];
//this.togglePause(true);
this.currentTrackIndex = -1;
this.setState({
activeTrackIndex: -1,
displayedTime: 0
}, () => {
this.togglePause(true);
});
}
from cassette.
@MichaelLeeHobbs alright - for future reference though, I would love a semi-thorough description of what you see to be the problem with the player's current implementation, so that I could make it better.
from cassette.
If you have an example repo demonstrating the problem that would be ideal - perhaps you could direct to an earlier commit where you were experiencing said problem so I could take a look?
from cassette.
I'm re-reading this thread and it makes sense to me now.
The simple solution to your problem is to check for playlist equality (===
) in componentWillReceiveProps
, and return if so.
This brings up a few other questions though -
- Currently, if the new playlist prop is falsy, it gets ignored. This seems contrary to React principles, so perhaps that should result in the playlist stopping or fading out?
- If we agreed on the playlist equality test, does that mean a playlist that is deeply equal but not equal-equal should reset the player? For example, what if your application triggers a new playlist async fetch and at the end the Redux builds a new copy of the same playlist? Should the default behavior be to reset?
- Further, if we decide NO it should not reset, how about a playlist which is different but contains the song which is already playing? I wonder if we should preserve playback but change the index of the currently playing song to match its index in the new playlist.
Perhaps some config options should be available to change this behavior but I am leaning toward allowing continuous playback for new playlists as long as the current track is still in it.
from cassette.
I decided to go ahead and make the changes I described. The original issue should be resolved, and the player should work better in general when swapping playlists. See #10.
from cassette.
Related Issues (20)
- Add Sass section to @cassette/player docs
- Update CONTRIBUTING doc
- ContextProvider/Consumer not working as expected HOT 22
- Google Chrome - Rewind media not working HOT 6
- Address getting started pain points
- Remove support for unsupported `displayText` property on track
- Officially migrate to @cassette packages on npm
- Example: fork Webamp and adapt to use Cassette
- Timidity midi playback plug-in (?)
- How can context updates be streamlined to cut out extraneous work?
- Handling media element errors HOT 6
- Let PlayerContextGroup handle media outside of Cassette
- Timestamp rounds up to nearest second, MediaStatusBar momentarily reads :60 HOT 2
- Set up Cypress for testing HOT 1
- Need help, not sure if I'm doing everything right. HOT 6
- Snapshot not updating PlayerContextProvider state when playlist changes. HOT 7
- Snapshot not updating PlayerContextProvider state if playlist contains different track urls HOT 5
- Setting index in PlayerContextProvider outside HOT 6
- Correct way to set pause after a track is finished but before jumping to the next HOT 1
- onSelectTrackIndex always starts playing HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from cassette.