-
Notifications
You must be signed in to change notification settings - Fork 14
PLAT-80843: Add Shaka Video Player sample #81
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
Open
teckliew
wants to merge
7
commits into
develop
Choose a base branch
from
feature/PLAT-80843
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
5fb5cc6
add pattern-shaka-video-player
7e07443
spaces to tabs and move initPlayer into decorator
5da15ec
config for shaka player
f32ae8f
bit of clean up
a155db6
fix up exports
e2d0495
update dependencies and documentation
cd12284
bind onError
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| # See http://help.github.com/ignore-files/ for more about ignoring files. | ||
|
|
||
| # dependencies | ||
| node_modules | ||
|
|
||
| # testing | ||
| coverage | ||
|
|
||
| # production | ||
| build | ||
| dist | ||
|
|
||
| # misc | ||
| .DS_Store | ||
| npm-debug.log |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| ## Shaka Video Player pattern | ||
|
|
||
| A sample Enact application that demonstrates how to use [shaka-player](https://shaka-player-demo.appspot.com/docs/api/index.html). | ||
|
|
||
| Run `npm install` then `npm run serve` to have the app running on [http://localhost:8080](http://localhost:8080), where you can view it in your browser. | ||
|
|
||
| --- | ||
|
|
||
| This project was bootstrapped with the Enact [cli](https://github.com/enactjs/cli). |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| { | ||
| "name": "shaka-app", | ||
| "version": "1.0.0", | ||
| "description": "A sample Enact app that showcases a VideoPlayer powered by Shaka Player", | ||
| "author": "@teckliew", | ||
| "main": "src/index.js", | ||
| "scripts": { | ||
| "serve": "enact serve", | ||
| "pack": "enact pack", | ||
| "pack-p": "enact pack -p", | ||
| "watch": "enact pack --watch", | ||
| "clean": "enact clean", | ||
| "lint": "enact lint .", | ||
| "license": "enact license", | ||
| "test": "enact test", | ||
| "test-watch": "enact test --watch" | ||
| }, | ||
| "license": "Apache-2.0", | ||
| "private": true, | ||
| "repository": "", | ||
| "enact": { | ||
| "theme": "moonstone" | ||
| }, | ||
| "eslintConfig": { | ||
| "extends": "enact" | ||
| }, | ||
| "eslintIgnore": [ | ||
| "node_modules/*", | ||
| "build/*", | ||
| "dist/*" | ||
| ], | ||
| "dependencies": { | ||
| "@enact/core": "^3.0.0-beta.1", | ||
| "@enact/i18n": "^3.0.0-beta.1", | ||
| "@enact/moonstone": "^3.0.0-beta.1", | ||
| "@enact/spotlight": "^3.0.0-beta.1", | ||
| "@enact/ui": "^2.0.0", | ||
| "ilib": "^14.3.0", | ||
| "prop-types": "^15.6.2", | ||
| "react": "^16.8.0", | ||
| "react-dom": "^16.8.0", | ||
| "shaka-player": "^2.5.2" | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| { | ||
| "files": [] | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| import kind from '@enact/core/kind'; | ||
| import MoonstoneDecorator from '@enact/moonstone/MoonstoneDecorator'; | ||
| import Panels from '@enact/moonstone/Panels'; | ||
| import React from 'react'; | ||
|
|
||
| import MainPanel from '../views/MainPanel'; | ||
|
|
||
| import css from './App.module.less'; | ||
|
|
||
| const App = kind({ | ||
| name: 'App', | ||
|
|
||
| styles: { | ||
| css, | ||
| className: 'app' | ||
| }, | ||
|
|
||
| render: (props) => ( | ||
| <div {...props}> | ||
| <Panels> | ||
| <MainPanel /> | ||
| </Panels> | ||
| </div> | ||
| ) | ||
| }); | ||
|
|
||
| export default MoonstoneDecorator(App); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| .app { | ||
| // styles can be put here | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| { | ||
| "main": "App.js" | ||
| } |
89 changes: 89 additions & 0 deletions
89
pattern-shaka-video-player/src/components/ShakaVideoPlayer.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,89 @@ | ||
| import {forward, handle} from '@enact/core/handle'; | ||
| import hoc from '@enact/core/hoc'; | ||
| import VideoPlayer from "@enact/moonstone/VideoPlayer"; | ||
| import PropTypes from 'prop-types'; | ||
| import React from 'react'; | ||
| import shaka from 'shaka-player'; | ||
|
|
||
| const ShakaVideoPlayerDecorator = hoc((config, Wrapped) => { | ||
| return class extends React.Component { | ||
| static displayName = 'ShakaVideoPlayerDecorator' | ||
|
|
||
| static propTypes = { | ||
| config: PropTypes.object, | ||
| manifestUri: PropTypes.string, | ||
| onError: PropTypes.func | ||
| } | ||
|
|
||
| componentDidMount () { | ||
| // Install built-in polyfills to patch browser incompatibilities. | ||
| shaka.polyfill.installAll(); | ||
|
|
||
| // Check to see if the browser supports the basic APIs Shaka needs. | ||
| if (shaka.Player.isBrowserSupported()) { | ||
| // Everything looks good! | ||
| this.initPlayer(); | ||
| } else { | ||
| // This browser does not have the minimum set of APIs we need. | ||
| console.error('Browser not supported!'); | ||
| } | ||
| } | ||
|
|
||
| onErrorEvent = (event) => { | ||
| // Extract the shaka.util.Error object from the event. | ||
| this.onError(event.detail); | ||
| } | ||
|
|
||
| onError = handle( | ||
| forward('onError') | ||
| ).bindAs(this, 'onError') | ||
|
|
||
| initPlayer = () => { | ||
| // Create a Player instance with videoNode. | ||
| const player = new shaka.Player(this.videoNode); | ||
|
|
||
| // Listen for error events. | ||
| player.addEventListener('error', this.onErrorEvent); | ||
|
|
||
| // Try to load a manifest. | ||
| // This is an asynchronous process. | ||
| player | ||
| .load(this.props.manifestUri) | ||
| .then(function () { | ||
| // This runs if the asynchronous load is successful. | ||
| console.log('The video has now been loaded!'); | ||
| }) | ||
| .catch(this.onError); // onError is executed if the asynchronous load fails. | ||
|
|
||
| // Configuration for the player here | ||
| // https://shaka-player-demo.appspot.com/docs/api/tutorial-config.html | ||
| const playerConfig = {...config, ...this.props.config}; | ||
| player.configure(playerConfig); | ||
| } | ||
|
|
||
| setWrappedRef = (node) => { | ||
| if (node && node.getVideoNode) { | ||
| // By default, moonstone/VideoPlayer uses ui/Media for its videoComponent. To get | ||
| // the underlying <video> node, we're using the private `media` member. | ||
| this.videoNode = node.getVideoNode().media; | ||
| } | ||
| } | ||
|
|
||
| render () { | ||
| const props = {...this.props}; | ||
|
|
||
| delete props.config; | ||
| delete props.manifestUri; | ||
|
|
||
| return <Wrapped {...props} ref={this.setWrappedRef} /> | ||
| } | ||
| } | ||
| }); | ||
|
|
||
| const ShakaVideoPlayer = ShakaVideoPlayerDecorator(VideoPlayer); | ||
|
|
||
| export default ShakaVideoPlayer; | ||
| export { | ||
| ShakaVideoPlayer, | ||
| ShakaVideoPlayerDecorator | ||
| }; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| import React from 'react'; | ||
| import {render} from 'react-dom'; | ||
| import App from './App'; | ||
|
|
||
| const appElement = (<App />); | ||
|
|
||
| // In a browser environment, render instead of exporting | ||
| if (typeof window !== 'undefined') { | ||
| render(appElement, document.getElementById('root')); | ||
| } | ||
|
|
||
| export default appElement; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| import kind from '@enact/core/kind'; | ||
| import {Panel, Header} from '@enact/moonstone/Panels'; | ||
| import React from 'react'; | ||
| import ShakaVideoPlayer from '../components/ShakaVideoPlayer'; | ||
|
|
||
| const sintelManifestUri = 'https://storage.googleapis.com/shaka-demo-assets/sintel/dash.mpd'; | ||
| const playerConfig = { | ||
| preferredAudioLanguage: 'en-US', | ||
| playRangeStart: 420 | ||
| }; | ||
|
|
||
| const MainPanel = kind({ | ||
| name: 'MainPanel', | ||
|
|
||
| render: (props) => ( | ||
| <Panel {...props}> | ||
| <Header title="VideoPlayer" titleBelow="powered by Shaka Player" /> | ||
| <ShakaVideoPlayer | ||
| config={playerConfig} | ||
| manifestUri={sintelManifestUri} | ||
| /> | ||
| </Panel> | ||
| ) | ||
| }); | ||
|
|
||
| export default MainPanel; |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this the right way to bind the handler?