Repository navigation
Expand file tree
/
Copy pathLiveStream.tsx
More file actions
147 lines (126 loc) · 4.69 KB
/
Copy pathLiveStream.tsx
File metadata and controls
147 lines (126 loc) · 4.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
/*
* This code and all components (c) Copyright 2025, Wowza Media Systems, LLC. All rights reserved.
* This code is licensed pursuant to the Wowza Public License version 1.0, available at https://github.com/WowzaMediaSystems/dev-guides/blob/main/LICENSE.txt.
*/
import { useState, useRef, useEffect } from "react";
import "@flowplayer/player/flowplayer.css";
import Flowplayer, { useFlowplayer } from "@flowplayer/react-flowplayer";
import {
PAUSE,
PLAYING,
STANDARD_ERROR,
ENDED,
ERROR,
} from "@flowplayer/player/core/events";
import type { Player } from "@flowplayer/player";
import { setupFlowplayer } from "@/lib/setup-flowplayer";
import { DEFAULT_LIVESTREAM_URL, FLOWPLAYER_TOKEN } from "../config";
import { ScrollArea } from "@/components/ui/scroll-area";
import { Card } from "@/components/ui/card";
import Typewriter from "typewriter-effect";
import Header from "@/components/Header";
import Footer from "@/components/Footer";
export default function LiveStreamPage() {
const playerRef = useRef<HTMLDivElement | null>(null);
const player = useFlowplayer(playerRef) as Player;
setupFlowplayer("hls", "subtitles");
const [demoPlaybackState, setDemoPlaybackState] = useState("paused");
const [videoUrl, setVideoUrl] = useState<string | undefined>(
DEFAULT_LIVESTREAM_URL
);
const [captionText, setCaptionText] = useState<string>("");
const togglePlay = () => {
if (!player) return; // No API available
player.togglePlay();
};
const onHandleState = (ev: Event) => {
if (ev.type === PAUSE) setDemoPlaybackState("paused");
if (ev.type === PLAYING) setDemoPlaybackState("playing");
};
useEffect(() => {
if (!player) return;
player.on(PAUSE, onHandleState);
player.on(PLAYING, onHandleState);
player.on(STANDARD_ERROR, (e) => {
console.error("FLOWPLAYER - STANDARD_ERROR:", e);
});
player.on(ERROR, (e) => {
console.error("FLOWPLAYER - ERROR:", e);
});
player.on(ENDED, (e) => {
console.error("FLOWPLAYER - ENDED:", e);
});
// player.on(FINISHED, (e) => {
// console.error("FLOWPLAYER - FINISHED:", e);
// });
return () => {
// Cleanup on unmount
if (!player) return;
player.off(PAUSE, onHandleState);
player.off(PLAYING, onHandleState);
};
}, [player]);
return (
<div className="min-h-screen bg-gradient-subtle">
<Header />
<div className="container mx-auto px-4 py-8">
<div className="mb-8 text-center">
<h1 className="text-4xl font-bold text-foreground mb-4">
Wowza Live Streaming
</h1>
<p className="text-lg text-muted-foreground max-w-2xl mx-auto">
With Wowza Streaming Engine
</p>
</div>
<div className="grid grid-cols-1 lg:grid-cols-2 gap-8 max-w-7xl mx-auto items-start">
{/* Video Player Section */}
<div className="space-y-4 order-1">
<Card className="p-0 overflow-hidden shadow-video">
<div className="relative aspect-video bg-muted">
<Flowplayer
src={videoUrl}
token={FLOWPLAYER_TOKEN}
ref={playerRef}
opts={{
ui: 1024,
asel: true,
fullscreen: false,
autoplay: true,
lang: "en",
}}
onError={(error) => {
console.error("Flowplayer component error:", error);
}}
/>
</div>
</Card>
</div>
<div className="space-y-4 order-3 lg:order-2">
<Card className="shadow-elegant aspect-video flex flex-col">
<div className="space-y-6">
<div className="text-center mt-4">
<p className="text-sm text-muted-foreground mb-2">
Here is the playback URL of the stream from Wowza Streaming
Engine, configured in the config.ts file of this project.
</p>
<span className="inline-flex items-center justify-center px-4 py-2 bg-primary/10 text-primary text-sm font-mono rounded-md">
{videoUrl}
</span>
</div>
</div>
</Card>
</div>
</div>
</div>
<div className="mb-8 text-center">
<p className="text-sm text-muted-foreground mb-2">
Source code for this demo is available on GitHub: <br />{" "}
<a href="https://github.com/WowzaMediaSystems/dev-guides">
https://github.com/WowzaMediaSystems/dev-guides
</a>
</p>
</div>
<Footer />
</div>
);
}