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

Closes issue #222. Autoplay of suggested next video. Button toggle. Does not play duplicates by maintaining history of all videos. #231

Closed
wants to merge 15 commits into from

Conversation

cipher1729
Copy link

Provide a general summary of your changes in the Title above.

Important

Mark with [x] to select. Leave as [ ] to unselect.

Motivation and Context

  • Why is this change required? What problem does it solve?
  • If it fixes an open issue, include the text Closes #1 (where 1 would be the issue number) to your commit message.
    Closes Autoplay Feature from Youtube #222

Types of changes

What types of changes does your code introduce? Check all the boxes that apply:

  • Bug fix (non-breaking change which fixes an issue)
  • [ x] New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Description

  • Describe your changes in detail.
    Added an autoplay button with two states - 'start autoplay' and 'stop autoplay'. With autoplay ON, similar videos keep playing one after the other. 'stop autoplay' disables this feature. History of videos played till now is stored and accessed from local session storage.

Final checklist:

Go over all the following points and check all the boxes that apply
If you're unsure about any of these, don't hesitate to ask. We're here to help!

  • [x ] My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • [x ] I have read the CONTRIBUTING guidelines.
  • All tests passed.

Last two tests "Demo" and "Form" fail - they complain about actions performed on null DOM objects. Maybe it has something to do with the order the player components and the page itself are loaded. The Demo still works, if the button is clicked manually.

var playList = [];
var autoplayState;


Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: too many blank lines

@shakeelmohamed
Copy link
Member

shakeelmohamed commented Jul 30, 2016

Thanks for the efforts here @cipher1729!

Last two tests "Demo" and "Form" fail - they complain about actions performed on null DOM objects. Maybe it has something to do with the order the player components and the page itself are loaded. The Demo still works, if the button is clicked manually.

If these tests are failing, functionality is broken.

  • I will update the eslint settings to catch some of the style issues I commented on (edit: done)
  • Maybe we should be using window.localStorage instead, this will persist the playlist a bit longer - if so we need an easy way to purge the playlist information.
  • I think we shouldn't write to either storage more than once per function as there's a (relatively low) performance cost, but more importantly it will bloat the code.
  • Since we're using multiple window.sessionStorage keys, I think it might be cleaner to just use 1 key for playlist information and serialize a more detailed JSON object. Intuitively, something like the following seems reasonable:
{
    "items": [
        {
            "type": "youtube",
            "id": "12345678911",
            "played": false
        }
    ],
    "autoplaying": false
}

I'm always open to suggestions 💭

@cipher1729
Copy link
Author

cipher1729 commented Aug 2, 2016

Thanks for the feedback @shakeelmohamed . I'll try to fix issues asap

@@ -580,32 +573,32 @@ $(function() {
// How do we know if the value is truly invalid?
// Preload the form from the URL
var currentVideoID = getCurrentVideoID();
if (currentVideoID) {
if (currentVideoID)
{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please put the brace at the end of the previous line (with a space after the ))

…" : "true"/"false" , items=[ {"type":"youtube", "id":videoId, "played":true}, ... ] }
$("#toggleAutoplay").click(function(event)
{
var toggleTextElement = $("#" + event.currentTarget.id);
if (autoplayState === null)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code can be simplified by using an if condition of !!autoplayState which converts the value to a boolean, null will evaluate to false.

ie:

> var vals = [null, false, true];
undefined
> for (var v in vals) { console.log(!!vals[v]); }
false
false
true

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like your logic but eslint complains: "Redundant double negation"

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In that case, just use autoplayState as the condition. The same boolean rules will apply inside an if/loop condition

@shakeelmohamed
Copy link
Member

I've made some additional eslint changes, please merge in the latest master branch. This will catch many of the style-related things I would've commented on

@cipher1729
Copy link
Author

I think i've incorporated all changes

toggleTextElement.text("Stop autoplay");
}
else {
if (autoplayState === "true")
{
if (autoplayState === true) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't need to compare a truthy value to true, it can just be if (autoplayState) {

Copy link
Member

@shakeelmohamed shakeelmohamed left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cipher1729 ping 😃

@cipher1729
Copy link
Author

Hey @shakeelmohamed , sorry been crazy busy, will get back to this asap

avalan4e57 added a commit to avalan4e57/zen-audio-player.github.io that referenced this pull request Jul 28, 2017
Cleaned up the code from pull request zen-audio-player#231.
Then fixed some bugs:
(1) Fixed getNewVideoID function. Previously it just popped up all
the playList and left only the first element. And if this element
would be current video id then nextId will be set to null. Now I've
made a reverse for playlist array to get just the same next video from
YouTube as Youtube suggests itself and that is done with no further
changes in the code. I've also removed the while loop from
getNewVideoID function and that gives the code an opportunity
to check all the playlist for a next track during the session.
(2) Fixed the problem when tracks were added to videoMetadata["items"]
when they were already there. Now there is a clause that checks if
current track has already been played and if so just doesn't add
a duplicate.
@shakeelmohamed
Copy link
Member

Closing due to inactivity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Autoplay Feature from Youtube
2 participants