Skip to content

Instantly share code, notes, and snippets.

View PatrickKalkman's full-sized avatar

Patrick Kalkman PatrickKalkman

View GitHub Profile
@PatrickKalkman
PatrickKalkman / splash.py
Created June 12, 2021 12:37
The splash game state
class Splash(BaseState):
def __init__(self):
super(Splash, self).__init__()
self.title = self.font.render("PyGalaga", True, pygame.Color("blue"))
self.title_rect = self.title.get_rect(center=self.screen_rect.center)
self.next_state = "MENU"
self.time_active = 0
def update(self, dt):
self.time_active += dt
@PatrickKalkman
PatrickKalkman / run.py
Created June 12, 2021 10:35
the main game loop of the game
def run(self):
while not self.done:
dt = self.clock.tick(self.fps)
self.event_loop()
self.update(dt)
self.draw()
pygame.display.update()
@PatrickKalkman
PatrickKalkman / basestate.py
Created June 12, 2021 10:20
Base class for each state of the state machine
class BaseState(object):
def __init__(self):
self.done = False
self.quit = False
self.next_state = None
self.screen_rect = pygame.display.get_surface().get_rect()
self.font = pygame.font.Font(None, 32)
def startup(self):
pass
class BaseState(object):
def __init__(self):
self.done = False
self.quit = False
self.next_state = None
self.screen_rect = pygame.display.get_surface().get_rect()
self.font = pygame.font.Font(None, 32)
def startup(self):
pass
@PatrickKalkman
PatrickKalkman / drm.js
Created May 15, 2021 18:56
Add Widevine and Fairplay DRM
const cert = fetch("YOUR FAIRPLAY CERTIFICATE URL");
if (this.platform.SAFARI) {
this.player.configure({
preferredAudioLanguage: 'en-US',
drm: {
servers: {
'com.apple.fps.1_0': '[fairplay license server URL]',
},
advanced: {
@PatrickKalkman
PatrickKalkman / subtitles.js
Created May 15, 2021 18:23
Loading and selecting subtitles
let captionUrl = "http://amssamples.streaming.mediaservices.windows.net/bc57e088-27ec-44e0-ac20-a85ccbcd50da/TOS-en.vtt";
this.player
.load(videoUrl)
.then(() => {
this.player.addTextTrackAsync(captionUrl, "en", "subtitle", 'text/vtt').then(() => {{
const textTracks = this.player.getTextTracks();
if (textTracks.length > 0) {
this.player.setTextTrackVisibility(true);
this.player.selectTextTrack(textTracks[0]);
}
@PatrickKalkman
PatrickKalkman / select-video.js
Created May 15, 2021 17:31
Using the Platform module to detect
let videoUrl = "http://www.bok.net/dash/tears_of_steel/cleartext/stream.mpd";
if (this.platform.SAFARI) {
videoUrl = "http://demo.unified-streaming.com/video/tears-of-steel/tears-of-steel.ism/.m3u8";
}
this.player
.load(videoUrl)
.then(() => {
this.videoElement?.play();
})
<div id="videoContainer" #videoContainer class="amsterdam-acid-blue">
<video #videoPlayer id="videoPlayer" width="100%" height="100%">
</video>
</div>
@PatrickKalkman
PatrickKalkman / init-player.js
Created May 14, 2021 18:52
function to initialize shaka-player
private initPlayer() {
this.player = new shaka.Player(this.videoElement);
const ui = new shaka.ui.Overlay(
this.player,
this.videoContainerElement,
this.videoElement
);
this.player
@PatrickKalkman
PatrickKalkman / shaka-player-component.js
Created May 14, 2021 18:33
shaka player typescript file
import { Component, AfterViewInit, ElementRef, ViewChild } from '@angular/core';
declare let shaka: any;
@Component({
selector: 'app-shaka-player',
templateUrl: './shaka-player.component.html',
styleUrls: ['./shaka-player.component.css'],
})
export class ShakaPlayerComponent implements AfterViewInit {
@ViewChild('videoPlayer') videoElementRef: ElementRef | undefined;