feat: 新增跌倒影片播放

This commit is contained in:
2024-10-25 17:02:50 +08:00
parent 1c843b1dcc
commit 66690c3795
2 changed files with 73 additions and 4 deletions

View File

@@ -1,5 +1,8 @@
import 'package:flutter/material.dart';
import 'package:mysql_client/mysql_client.dart';
import 'package:video_player/video_player.dart';
import 'package:better_player_plus/better_player_plus.dart';
class HistoricalRecord extends StatefulWidget {
final String email; // 接收來自上個頁面的 email
@@ -166,11 +169,71 @@ class _HistoricalRecordState extends State<HistoricalRecord> {
}
// 新增詳細資料頁面
class FallDetailPage extends StatelessWidget {
class FallDetailPage extends StatefulWidget {
final Map<String, dynamic> fallDetail;
FallDetailPage({required this.fallDetail});
@override
State<FallDetailPage> createState() => _FallDetailPageState();
}
class _FallDetailPageState extends State<FallDetailPage> {
late BetterPlayerController _betterPlayerController;
String fhvideoId = '';
@override
void initState() {
super.initState();
BetterPlayerConfiguration betterPlayerConfiguration =
BetterPlayerConfiguration(
aspectRatio: 16 / 9,
fit: BoxFit.contain,
);
_betterPlayerController = BetterPlayerController(betterPlayerConfiguration);
_fetchData(); // 連資料庫
}
void dispose() {
super.dispose();
_betterPlayerController.dispose();
}
void _fetchData() async {
final conn = await MySQLConnection.createConnection(
host: '203.64.84.154',
port: 33061,
userName: 'root',
password: 'Topic@2024',
databaseName: 'care',
);
await conn.connect();
try {
var userNameResult = await conn.execute(// 使用傳遞過來的 email來找homeusername
'SELECT hfvideoId FROM HomeFallVideo WHERE hfallId = :fallId',
{'fallId': widget.fallDetail['跌倒編號']},
);
if (userNameResult.rows.isNotEmpty) {
fhvideoId = userNameResult.rows.first.colByName(
"hfvideoId").toString();
BetterPlayerDataSource dataSource = BetterPlayerDataSource(
BetterPlayerDataSourceType.network,
"https://streamer.comprehensiveguardian.software/stream/${fhvideoId}/playlist.m3u8",
videoFormat: BetterPlayerVideoFormat.hls,
);
_betterPlayerController.setupDataSource(dataSource);
}
} catch (e) {
print('Error: $e');
} finally {
await conn.close();
}
}
@override
Widget build(BuildContext context) {
return Scaffold(
@@ -184,12 +247,17 @@ class FallDetailPage extends StatelessWidget {
children: [
//Text('長者ID: ${fallDetail['長者ID']}', style: TextStyle(fontSize: 18)),
//SizedBox(height: 10),
Text('跌倒時間: ${fallDetail['跌倒時間']}', style: TextStyle(fontSize: 18)),
Text('跌倒時間: ${widget.fallDetail['跌倒時間']}', style: TextStyle(fontSize: 18)),
SizedBox(height: 10),
Text('跌倒原因: ${fallDetail['跌倒原因']}', style: TextStyle(fontSize: 18)),
Text('跌倒原因: ${widget.fallDetail['跌倒原因']}', style: TextStyle(fontSize: 18)),
SizedBox(height: 10),
Text('跌倒地點: ${fallDetail['跌倒地點']}', style: TextStyle(fontSize: 18)),
Text('跌倒地點: ${widget.fallDetail['跌倒地點']}', style: TextStyle(fontSize: 18)),
// 在這裡可以添加更多詳細資料
if (_betterPlayerController != null)
AspectRatio(
aspectRatio: 16 / 9,
child: BetterPlayer(controller: _betterPlayerController),
),
],
),
),

View File

@@ -43,6 +43,7 @@ dependencies:
persistent_bottom_nav_bar_v2: ^5.3.0
shared_preferences: ^2.2.3
validators: ^3.0.0
better_player_plus: ^1.0.7
dev_dependencies:
flutter_test: