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

feat: Export markers as JSON file #22

Merged
merged 1 commit into from
Aug 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,13 @@ class App extends Component {
- Markers creation, display and selection
- Jumping back and forth between frames based on FPS (default fps value is 30)
- Display various settings associated with the video player such as title, fps, volume, repeat, start time
- Export markers as JSON file.

### Props

Prop | Description | Default
---- | ----------- | -------
`controls` | Set visible controls. Available controls: ControlSelection | [ControlSelection.Play, ControlSelection.Time, ControlSelection.Progress, ControlSelection.Volume, ControlSelection.FullScreen]
`controls` | Set visible controls. Available controls: ControlSelection | [ControlSelection.Play, ControlSelection.Time, ControlSelection.Progress, ControlSelection.Volume, ControlSelection.FullScreen, ControlSelection.AddMarker, ControlSelection.ExportMarkers]
`height` | Set the height of the player | '360px'
`width` | Set the width of the player | '640px'
`isPlaying` | Set to `true` or `false` to play or pause the media | false
Expand Down
2 changes: 1 addition & 1 deletion dist/index.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions dist/utils/download-attachment.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export declare function downloadAttachment(data: string, fileName: string): void;
export declare function downloadAttachmentFromUrl(url: string, fileName: string): void;
1 change: 1 addition & 0 deletions dist/utils/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { downloadAttachment } from './download-attachment';
4 changes: 4 additions & 0 deletions example/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ function App() {
id: 'AddMarker',
title: 'Add Marker',
},
{
id: 'ExportMarkers',
title: 'Export Markers',
},
]

const settingsList = [
Expand Down
43 changes: 39 additions & 4 deletions example/bundle.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": "react-video-player-extended",
"version": "8.0.0",
"version": "8.1.0",
"description": "React HTML5 video providing functionality for marking and selecting frames, jumping back and forth between frames based on the fps.",
"author": "Amitt K Sharma",
"license": "MIT",
Expand Down
15 changes: 15 additions & 0 deletions src/controls.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as React from 'react'
import { Marker, MarkerConfiguration, MarkerView } from './marker'
import { downloadAttachment } from './utils'

enum ControlsSelection {
FullScreen = 'FullScreen',
Expand All @@ -10,6 +11,7 @@ enum ControlsSelection {
LastFrame = 'LastFrame',
NextFrame = 'NextFrame',
AddMarker = 'AddMarker',
ExportMarkers = 'ExportMarkers',
}

interface Props {
Expand Down Expand Up @@ -141,6 +143,19 @@ export class Controls extends React.Component<Props, never> {
})}
</div>
)}
{controls.indexOf(ControlsSelection.ExportMarkers.toString()) !== -1 && (
<button
className="export-markers"
onClick={() =>
downloadAttachment(
JSON.stringify(markers, null, 2),
`Markers_${new Date().toISOString().substring(0, 10)}.json`,
)
}
>
Export
</button>
)}
{controls.indexOf(ControlsSelection.Volume.toString()) !== -1 && (
<div className="volume-wrap">
<progress ref={volumeEl} max="100" value={volume * 100} onClick={onVolumeClick}>
Expand Down
41 changes: 41 additions & 0 deletions src/images/export-markers.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 7 additions & 1 deletion src/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
background-position: center center;
border: 0;
cursor: pointer;
margin: 10px 7px;
margin: 10px 5px;
padding: 0;
outline: none;
height: 16px;
Expand Down Expand Up @@ -86,6 +86,12 @@
width: 15px;
}

.react-video-controls .export-markers {
background-image: url('./images/export-markers.svg');
background-position-x: 0;
margin-top: 8px;
width: 17px;
}

.react-video-controls .time {
color: #969696;
Expand Down
11 changes: 11 additions & 0 deletions src/utils/download-attachment.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
export function downloadAttachment(data: string, fileName: string) {
const url = window.URL.createObjectURL(new Blob([data]))
downloadAttachmentFromUrl(url, fileName)
}

export function downloadAttachmentFromUrl(url: string, fileName: string) {
const link = document.createElement('a')
link.href = url
link.setAttribute('download', fileName)
link.click()
}
1 change: 1 addition & 0 deletions src/utils/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { downloadAttachment } from './download-attachment'