Skip to content

Commit

Permalink
Cancel requests on source change (Fixes #174)
Browse files Browse the repository at this point in the history
  • Loading branch information
Sam Potts committed Feb 28, 2016
1 parent 1bbc47c commit cd83a26
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 10 deletions.
18 changes: 18 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,23 @@
# Changelog

## v1.5.16
- Cancel requests on source change (Fixes #174)

## v1.5.15
- Fix for CustomEvent polyfill and related bug (See #172)

## v1.5.14
- Volume storage fix (Fixes #171)

## v1.5.13
- Fix for manual caption rendering

## v1.5.12
- Added a duration option to pass the duration of the file
- Added the ability to set options per element by setting a data-plyr attribute on the target elements (this might be useful for the duration option for example)
- Fixes for Chrome and Safari caption rendering, they now use the default texttrack and cuechange events
- Firefox bug fix for event not defined

## v1.5.11
- iOS embed bug fixes (fixes #166)
- Hide IE/Edge <input type='range'> tooltip (since we have a styled one) (fixes #160)
Expand Down
4 changes: 2 additions & 2 deletions dist/plyr.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "plyr",
"version": "1.5.15",
"version": "1.5.16",
"description": "A simple, accessible and customizable HTML5, YouTube and Vimeo media player",
"homepage": "http://plyr.io",
"main": "src/js/plyr.js",
Expand Down
10 changes: 5 additions & 5 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ If you have any cool ideas or features, please let me know by [creating an issue

Check `docs/index.html` and `docs/dist/docs.js` for an example setup.

**Heads up:** the example `index.html` file needs to be served from a webserver (such as Apache, Nginx, IIS or similar) unless you change the file sources to include http or https. e.g. change `//cdn.plyr.io/1.5.15/plyr.js` to `https://cdn.plyr.io/1.5.15/plyr.js`
**Heads up:** the example `index.html` file needs to be served from a webserver (such as Apache, Nginx, IIS or similar) unless you change the file sources to include http or https. e.g. change `//cdn.plyr.io/1.5.16/plyr.js` to `https://cdn.plyr.io/1.5.16/plyr.js`

### Node Package Manager (NPM)
Using NPM, you can grab Plyr:
Expand Down Expand Up @@ -69,11 +69,11 @@ More info is on [npm](https://www.npmjs.com/package/ember-cli-plyr) and [GitHub]
If you want to use our CDN, you can use the following:

```html
<link rel="stylesheet" href="https://cdn.plyr.io/1.5.15/plyr.css">
<script src="https://cdn.plyr.io/1.5.15/plyr.js"></script>
<link rel="stylesheet" href="https://cdn.plyr.io/1.5.16/plyr.css">
<script src="https://cdn.plyr.io/1.5.16/plyr.js"></script>
```

You can also access the `sprite.svg` file at `https://cdn.plyr.io/1.5.15/sprite.svg`.
You can also access the `sprite.svg` file at `https://cdn.plyr.io/1.5.16/sprite.svg`.

### CSS & Styling
If you want to use the default css, add the `plyr.css` file from `/dist` into your head, or even better use `plyr.less` or `plyr.sass` file included in `/src` in your build to save a request.
Expand Down Expand Up @@ -175,7 +175,7 @@ Be sure to [validate your caption files](https://quuz.org/webvtt/)
Here's an example of a default setup:

```html
<script src="https://cdn.plyr.io/1.5.15/plyr.js"></script>
<script src="https://cdn.plyr.io/1.5.16/plyr.js"></script>
<script>plyr.setup();</script>
```

Expand Down
32 changes: 30 additions & 2 deletions src/js/plyr.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// ==========================================================================
// Plyr
// plyr.js v1.5.15
// plyr.js v1.5.16
// https://github.com/selz/plyr
// License: The MIT License (MIT)
// ==========================================================================
Expand Down Expand Up @@ -2225,6 +2225,9 @@
_remove(plyr.videoContainer);
}

// Cancel current network requests
_cancelRequests();

// Remove the old media
_remove(plyr.media);

Expand Down Expand Up @@ -2521,6 +2524,31 @@
});
}

// Cancel current network requests
// See https://github.com/Selz/plyr/issues/174
function _cancelRequests() {
if(!_inArray(config.types.html5, plyr.type)) {
return;
}

// Set empty src attribute
plyr.media.setAttribute('src', '');

// Remove child sources
var sources = plyr.media.querySelectorAll('source');
for (var i = 0; i < sources.length; i++) {
_remove(sources[i]);
}

// Load the new empty source
// This will cancel existing requests
// See https://github.com/Selz/plyr/issues/174
plyr.media.load();

// Debugging
_log("Cancelled network requests for old media");
}

// Destroy an instance
// Event listeners are removed when elements are removed
// http://stackoverflow.com/questions/12528049/if-a-dom-element-is-removed-are-its-listeners-also-removed-from-memory
Expand All @@ -2547,7 +2575,7 @@

// If video, we need to remove some more
if (plyr.type === 'video') {
// Remove captions
// Remove captions container
_remove(_getElement(config.selectors.captions));

// Remove video wrapper
Expand Down

0 comments on commit cd83a26

Please sign in to comment.