Skip to content

Commit

Permalink
feat: add muted autoplay (#92)
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaoyuhen authored May 13, 2019
1 parent a1926bf commit 7bbc7da
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 22 deletions.
1 change: 1 addition & 0 deletions example/mp4/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ const props = {
cover: 'https://zhstatic.zhihu.com/cfe/griffith/zhihu2018.jpg',
duration,
sources,
autoplay: true,
shouldObserveResize: true,
src: 'https://zhstatic.zhihu.com/cfe/griffith/zhihu2018_sd.mp4',
}
Expand Down
1 change: 1 addition & 0 deletions packages/griffith/README-zh-Hans.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ render(<Player {...props} />)
| `initialObjectFit` | `fill \| \contain \| cover \| none \| scale-down` | `contain` | object-fit 参数 |
| `useMSE` | `boolean` | `false` | 是否启用 MSE |
| `locale` | `en \| ja \| zh-Hans \| zh-Hant` | `en` | 界面语言 |
| `autoplay` | `boolean` | `false` | 自动播放(自动播放时会静音) |

`sources` 字段:

Expand Down
1 change: 1 addition & 0 deletions packages/griffith/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ render(<Player {...props} />)
| `initialObjectFit` | `fill \| contain \| cover \| none \| scale-down` | `contain` | object-fit |
| `useMSE` | `boolean` | `false` | Enable Media Source Extensions™ |
| `locale` | `en \| ja \| zh-Hans \| zh-Hant` | `en` | UI Locale |
| `autoplay` | `boolean` | `false` | Muted Autoplay |

`sources`:

Expand Down
11 changes: 11 additions & 0 deletions packages/griffith/src/components/Player/Player.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class Player extends Component {
static defaultProps = {
standalone: false,
duration: 0,
autoplay: false,
}

state = {
Expand Down Expand Up @@ -87,6 +88,16 @@ class Player extends Component {
ACTIONS.PLAYER.PAUSE,
this.handlePauseAction
)

const {autoplay} = this.props
if (autoplay && this.videoRef.current.root) {
if (!this.videoRef.current.root.muted) {
// Muted autoplay is always allowed
this.handleVideoVolumeChange(0)
}

this.handlePlay('video')
}
}

componentDidUpdate() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ const PlayerContainer = ({
initialObjectFit = 'contain',
useMSE,
locale = 'en',
autoplay,
}) => (
<ObjectFitProvider initialObjectFit={initialObjectFit}>
<PositionProvider shouldObserveResize={shouldObserveResize}>
Expand All @@ -37,6 +38,7 @@ const PlayerContainer = ({
{({currentSrc}) => (
<Player
useMSE={useMSE}
autoplay={autoplay}
standalone={standalone}
cover={cover}
title={title}
Expand Down
4 changes: 2 additions & 2 deletions website/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
"gatsby-transformer-remark": "^2.3.11",
"griffith": "1.4.3",
"normalize.css": "^8.0.1",
"react": "^16.8.6",
"react-dom": "^16.8.6",
"react": "16.4.2",
"react-dom": "16.4.2",
"react-helmet": "^5.2.0"
}
}
20 changes: 0 additions & 20 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -12033,16 +12033,6 @@ react-dom@16.4.2:
object-assign "^4.1.1"
prop-types "^15.6.0"

react-dom@^16.8.6:
version "16.8.6"
resolved "https://registry.yarnpkg.com/react-dom/-/react-dom-16.8.6.tgz#71d6303f631e8b0097f56165ef608f051ff6e10f"
integrity sha512-1nL7PIq9LTL3fthPqwkvr2zY7phIPjYrT0jp4HjyEQrEROnw4dG41VVwi/wfoCneoleqrNX7iAD+pXebJZwrwA==
dependencies:
loose-envify "^1.1.0"
object-assign "^4.1.1"
prop-types "^15.6.2"
scheduler "^0.13.6"

react-error-overlay@^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/react-error-overlay/-/react-error-overlay-3.0.0.tgz#c2bc8f4d91f1375b3dad6d75265d51cd5eeaf655"
Expand Down Expand Up @@ -12126,16 +12116,6 @@ react@16.4.2:
object-assign "^4.1.1"
prop-types "^15.6.0"

react@^16.8.6:
version "16.8.6"
resolved "https://registry.yarnpkg.com/react/-/react-16.8.6.tgz#ad6c3a9614fd3a4e9ef51117f54d888da01f2bbe"
integrity sha512-pC0uMkhLaHm11ZSJULfOBqV4tIZkx87ZLvbbQYunNixAAvjnC+snJCg0XQXn9VIsttVsbZP/H/ewzgsd5fxKXw==
dependencies:
loose-envify "^1.1.0"
object-assign "^4.1.1"
prop-types "^15.6.2"
scheduler "^0.13.6"

read-chunk@^3.0.0:
version "3.1.0"
resolved "https://registry.yarnpkg.com/read-chunk/-/read-chunk-3.1.0.tgz#4aab805e68b1b2c72a2fe5aefa8284faf623b1c0"
Expand Down

0 comments on commit 7bbc7da

Please sign in to comment.