{"id":19527033,"url":"https://github.com/kazemmdev/video-player","last_synced_at":"2026-06-18T07:31:57.103Z","repository":{"id":152458749,"uuid":"626090945","full_name":"kazemmdev/video-player","owner":"kazemmdev","description":null,"archived":false,"fork":false,"pushed_at":"2023-04-21T16:25:41.000Z","size":1278,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-10-05T13:17:46.505Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/kazemmdev.png","metadata":{"files":{"readme":"README.ts","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2023-04-10T19:24:19.000Z","updated_at":"2024-09-09T06:55:31.000Z","dependencies_parsed_at":"2023-07-26T23:51:58.525Z","dependency_job_id":null,"html_url":"https://github.com/kazemmdev/video-player","commit_stats":null,"previous_names":["k90mirzaei/video-player"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/kazemmdev/video-player","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kazemmdev%2Fvideo-player","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kazemmdev%2Fvideo-player/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kazemmdev%2Fvideo-player/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kazemmdev%2Fvideo-player/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kazemmdev","download_url":"https://codeload.github.com/kazemmdev/video-player/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kazemmdev%2Fvideo-player/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34481306,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-18T02:00:06.871Z","response_time":128,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-11T01:13:22.428Z","updated_at":"2026-06-18T07:31:57.089Z","avatar_url":"https://github.com/kazemmdev.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"// Sure, here's an example React component written in TypeScript that plays the HLS playlist you provided using the video.js library and the crypto-js library for decryption. This component follows the SOLID principles by separating concerns into smaller, more focused classes.\n\nimport React, { useEffect, useRef } from 'react';\nimport videojs, { VideoJsPlayerOptions } from 'video.js'\nimport CryptoJS from 'crypto-js';\n\ntype Props = {\n  playlistUrl: string;\n  keyUrl: string;\n};\n\nclass Decrypter {\n  private key: CryptoJS.WordArray;\n  private iv: CryptoJS.WordArray;\n\n  constructor(keyUrl: string, iv: string) {\n    const xhr = new XMLHttpRequest();\n    xhr.open('GET', keyUrl, false);\n    xhr.send();\n    const keyHex = xhr.responseText;\n    this.key = CryptoJS.enc.Hex.parse(keyHex);\n    this.iv = CryptoJS.enc.Hex.parse(iv);\n  }\n\n  decrypt(data: Uint8Array): Uint8Array {\n    const encrypted = CryptoJS.lib.WordArray.create(data);\n    const decrypted = CryptoJS.AES.decrypt({ ciphertext: encrypted }, this.key, { iv: this.iv });\n    return new Uint8Array(decrypted.sigBytes);\n  }\n}\n\nclass HlsPlaylist {\n  private segments: Array\u003c{ duration: number, uri: string, key?: { uri: string, iv: string } }\u003e;\n\n  constructor(playlistUrl: string) {\n    const xhr = new XMLHttpRequest();\n    xhr.open('GET', playlistUrl, false);\n    xhr.send();\n    const playlistText = xhr.responseText;\n    const lines = playlistText.trim().split('\\n');\n    const segments: Array\u003c{ duration: number, uri: string, key?: { uri: string, iv: string } }\u003e = [];\n    let currentKey: { uri: string, iv: string } | undefined = undefined;\n    for (let i = 0; i \u003c lines.length; i++) {\n      const line = lines[i];\n      if (line.startsWith('#EXT-X-KEY:')) {\n        const matches = /METHOD=AES-128,URI=\"([^\"]+)\",IV=([0-9a-fA-F]+)/.exec(line);\n        if (matches) {\n          currentKey = { uri: matches[1], iv: matches[2] };\n        } else {\n          console.warn('Could not parse key info:', line);\n        }\n      } else if (line.startsWith('#EXTINF:')) {\n        const matches = /^#EXTINF:([0-9.]+),/.exec(line);\n        if (matches) {\n          const duration = parseFloat(matches[1]);\n          const uri = lines[i + 1];\n          segments.push({ duration, uri, key: currentKey });\n          currentKey = undefined;\n        } else {\n          console.warn('Could not parse segment info:', line);\n        }\n      }\n    }\n    this.segments = segments;\n  }\n\n  getSegmentUrl(index: number): string | undefined {\n    return this.segments[index]?.uri;\n  }\n\n  getSegmentDuration(index: number): number | undefined {\n    return this.segments[index]?.duration;\n  }\n\n  getSegmentKey(index: number): Decrypter | undefined {\n    const keyInfo = this.segments[index]?.key;\n    if (keyInfo) {\n      return new Decrypter(keyInfo.uri, keyInfo.iv);\n    }\n  }\n\n  getSegmentCount(): number {\n    return this.segments.length;\n  }\n}\n\nclass HlsPlayer {\n  private playlist: HlsPlaylist;\n  private player: videojs.Player;\n  private currentSegment: number = 0;\n\n  constructor(playlistUrl: string, keyUrl: string, videoElement: HTMLVideoElement) {\n    this.playlist = new HlsPlaylist(playlistUrl);\n    const options: VideoJsPlayerOptions = {\n      sources: [{\n        src: this.playlist.getSegmentUrl(0) ?? '',\n        type: 'application/vnd.apple.mpegurl',\n      }],\n      html5: {\n        hls: {\n          overrideNative: true,\n          decrypt: (encrypted: Uint8Array, key: Uint8Array, iv: Uint8Array) =\u003e {\n            const decrypter = this.playlist.getSegmentKey(this.currentSegment);\n            if (decrypter) {\n              const decrypted = decrypter.decrypt(encrypted);\n              return decrypted.buffer;\n            } else {\n              console.warn('No key available for decryption');\n              return encrypted.buffer;\n            }\n          },\n        },\n      },\n      autoplay: true,\n    };\n    this.player = videojs(videoElement, options);\n    this.player.on('ended', () =\u003e {\n      this.currentSegment++;\n      if (this.currentSegment \u003c this.playlist.getSegmentCount()) {\n        const url = this.playlist.getSegmentUrl(this.currentSegment);\n        const duration = this.playlist.getSegmentDuration(this.currentSegment) ?? 0;\n        const key = this.playlist.getSegmentKey(this.currentSegment);\n        if (url) {\n          this.player.src({\n            src: url,\n            type: 'application/vnd.apple.mpegurl',\n          });\n          this.player.play();\n          if (duration \u003e 0) {\n            setTimeout(() =\u003e {\n              this.player.trigger('ended');\n            }, duration * 1000);\n          }\n        } else {\n          console.warn('No URL available for next segment');\n        }\n      } else {\n        console.log('Playlist ended');\n      }\n    });\n  }\n\n  start() {\n    this.player.play();\n  }\n}\n\nconst HlsPlayerComponent: React.FC\u003cProps\u003e = ({ playlistUrl, keyUrl }) =\u003e {\n  const videoRef = useRef\u003cHTMLVideoElement\u003e(null);\n\n  useEffect(() =\u003e {\n    if (!videoRef.current) {\n      console.warn('Video element not found');\n      return;\n    }\n    const player = new HlsPlayer(playlistUrl, keyUrl, videoRef.current);\n    player.start();\n  }, [playlistUrl, keyUrl]);\n\n  return (\n    \u003cdiv\u003e\n      \u003cvideo ref={videoRef} className=\"video-js vjs-default-skin vjs-big-play-centered\" playsInline /\u003e\n    \u003c/div\u003e\n  );\n};\n\nexport default HlsPlayerComponent;\n// To use this component, you can simply import it and render it like this:\n\nimport HlsPlayerComponent from './HlsPlayerComponent';\n\nconst App: React.FC = () =\u003e {\n  return (\n    \u003cdiv\u003e\n      \u003cHlsPlayerComponent playlistUrl=\"http://mydev.test/media/16/playlist.m3u8\" keyUrl=\"http://mydev.test/media/key/16/f12393361092e573.key\" /\u003e\n    \u003c/div\u003e\n  );\n};\n\nexport default App;\n// Note that this code assumes that the video.js and crypto-js libraries have been installed and imported correctly. You may need to adjust the import statements or add these libraries to your project if you encounter any errors.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkazemmdev%2Fvideo-player","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkazemmdev%2Fvideo-player","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkazemmdev%2Fvideo-player/lists"}