-
Notifications
You must be signed in to change notification settings - Fork 12
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
PLAT-80843: Add Shaka Video Player sample #81
base: develop
Are you sure you want to change the base?
Changes from 1 commit
5fb5cc6
7e07443
5da15ec
f32ae8f
a155db6
e2d0495
cd12284
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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 |
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). |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
{ | ||
"name": "shaka-app", | ||
"version": "1.0.0", | ||
"description": "A general template for an Enact Moonstone application.", | ||
"author": "", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Want to add your name here, Teck? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. :okay: |
||
"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": "UNLICENSED", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's make this apache like our others. |
||
"private": true, | ||
"repository": "", | ||
"enact": { | ||
"theme": "moonstone" | ||
}, | ||
"eslintConfig": { | ||
"extends": "enact" | ||
}, | ||
"eslintIgnore": [ | ||
"node_modules/*", | ||
"build/*", | ||
"dist/*" | ||
], | ||
"dependencies": { | ||
"@enact/core": "^2.0.0", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we update to 3.x? Add |
||
"@enact/i18n": "^2.0.0", | ||
"@enact/moonstone": "^2.0.0", | ||
"@enact/spotlight": "^2.0.0", | ||
"@enact/ui": "^2.0.0", | ||
"prop-types": "^15.6.2", | ||
"react": "^16.7.0", | ||
"react-dom": "^16.7.0", | ||
"shaka-player": "^2.5.2" | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"files": [] | ||
} |
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); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
.app { | ||
// styles can be put here | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"main": "App.js" | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
import hoc from '@enact/core/hoc'; | ||
import VideoPlayer from "@enact/moonstone/VideoPlayer"; | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import shaka from 'shaka-player'; | ||
|
||
function initPlayer(config, manifestUri) { | ||
// Create a Player instance. | ||
const video = document.querySelector('video'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I discovered the issue with I'm not sure we should expose that (it's not terrible but it isn't good either) but I think a "within React" impl (e.g. using |
||
const player = new shaka.Player(video); | ||
|
||
// Listen for error events. | ||
player.addEventListener('error', onErrorEvent); | ||
|
||
// Try to load a manifest. | ||
// This is an asynchronous process. | ||
player | ||
.load(manifestUri) | ||
.then(function() { | ||
// This runs if the asynchronous load is successful. | ||
console.log('The video has now been loaded!'); | ||
}) | ||
.catch(onError); // onError is executed if the asynchronous load fails. | ||
// Configure player | ||
player.configure(config); | ||
} | ||
|
||
function onErrorEvent(event) { | ||
// Extract the shaka.util.Error object from the event. | ||
onError(event.detail); | ||
} | ||
|
||
function onError(error) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's make this a bit more React-y by moving these handlers into the component and invoking callbacks via props as usual. Could then move the |
||
// Log the error. | ||
console.error('Error code', error.code, 'object', error); | ||
} | ||
|
||
const defaultConfig = { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should these be runtime props vs design time configs? |
||
preferredAudioLanguage: 'en-US', | ||
playRangeStart: 420 | ||
}; | ||
|
||
const ShakaPlayerDecorator = hoc(defaultConfig, (config, Wrapped) => { | ||
return class extends React.Component { | ||
static displayName = 'ShakaPlayerDecorator'; | ||
|
||
static propTypes = { | ||
manifestUri: PropTypes.string | ||
}; | ||
|
||
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! | ||
initPlayer(config, this.props.manifestUri); | ||
} else { | ||
// This browser does not have the minimum set of APIs we need. | ||
console.error('Browser not supported!'); | ||
} | ||
} | ||
|
||
render () { | ||
const props = Object.assign({}, this.props); | ||
delete props.manifestUri; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. spacing |
||
|
||
return <Wrapped {...props} /> | ||
} | ||
} | ||
}); | ||
|
||
const ShakaVideoPlayer = ShakaPlayerDecorator(VideoPlayer); | ||
|
||
export default ShakaVideoPlayer; |
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; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
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 MainPanel = kind({ | ||
name: 'MainPanel', | ||
|
||
render: (props) => ( | ||
<Panel {...props}> | ||
<Header title="VideoPlayer" titleBelow="powered by Shaka Player" /> | ||
<ShakaVideoPlayer autoPlay manifestUri={sintelManifestUri} /> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
</Panel> | ||
) | ||
}); | ||
|
||
export default MainPanel; |
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.
Let's update the description for completeness
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.
:yougotitdude: