From 0f487404e0ed6eb22f1250027d62ea1a3a94c72b Mon Sep 17 00:00:00 2001 From: Lukas Nagel Date: Sun, 3 Nov 2024 14:17:14 +0100 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20Refresh=20token=20on=20press=20play?= =?UTF-8?q?=20if=20needed?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/views/detail_views/episode_detail.dart | 35 ++-------------- lib/views/detail_views/movie_detail.dart | 35 ++-------------- lib/views/player.dart | 7 ++++ lib/widgets/play_button.dart | 48 ++++++++++++++++++++++ 4 files changed, 61 insertions(+), 64 deletions(-) create mode 100644 lib/widgets/play_button.dart diff --git a/lib/views/detail_views/episode_detail.dart b/lib/views/detail_views/episode_detail.dart index 682a32b..b6db53b 100644 --- a/lib/views/detail_views/episode_detail.dart +++ b/lib/views/detail_views/episode_detail.dart @@ -1,9 +1,8 @@ import 'package:flutter/material.dart'; import 'package:open_media_server_app/globals/globals.dart'; -import 'package:open_media_server_app/helpers/preferences.dart'; import 'package:open_media_server_app/models/internal/grid_item_model.dart'; -import 'package:open_media_server_app/views/player.dart'; import 'package:open_media_server_app/widgets/custom_image.dart'; +import 'package:open_media_server_app/widgets/play_button.dart'; class EpisodeDetailView extends StatelessWidget { const EpisodeDetailView({ @@ -61,36 +60,8 @@ class EpisodeDetailView extends StatelessWidget { const SizedBox( height: 16, ), - Center( - child: SizedBox( - width: double.infinity, - height: 40, - child: ElevatedButton.icon( - onPressed: () { - Navigator.push( - context, - MaterialPageRoute( - builder: (context) => PlayerView( - url: - "${Preferences.prefs?.getString("BaseUrl")}/stream/${itemModel.inventoryItem?.category}/${itemModel.inventoryItem?.id}"), - ), - ); - }, - icon: const Icon(Icons.play_arrow), - label: const Text("Play"), - style: ElevatedButton.styleFrom( - padding: const EdgeInsets.symmetric( - vertical: 8, - ), - textStyle: const TextStyle( - fontSize: 18, - fontWeight: FontWeight.w400, - ), - backgroundColor: Colors.white, - foregroundColor: Colors.black, - ), - ), - ), + PlayButton( + itemModel: itemModel, ), const SizedBox( height: 8, diff --git a/lib/views/detail_views/movie_detail.dart b/lib/views/detail_views/movie_detail.dart index 012a14c..9605d5d 100644 --- a/lib/views/detail_views/movie_detail.dart +++ b/lib/views/detail_views/movie_detail.dart @@ -1,9 +1,8 @@ import 'package:flutter/material.dart'; import 'package:open_media_server_app/globals/globals.dart'; -import 'package:open_media_server_app/helpers/preferences.dart'; import 'package:open_media_server_app/models/internal/grid_item_model.dart'; -import 'package:open_media_server_app/views/player.dart'; import 'package:open_media_server_app/widgets/custom_image.dart'; +import 'package:open_media_server_app/widgets/play_button.dart'; class MovieDetailView extends StatelessWidget { const MovieDetailView({ @@ -60,36 +59,8 @@ class MovieDetailView extends StatelessWidget { const SizedBox( height: 16, ), - Center( - child: SizedBox( - width: double.infinity, - height: 40, - child: ElevatedButton.icon( - onPressed: () { - Navigator.push( - context, - MaterialPageRoute( - builder: (context) => PlayerView( - url: - "${Preferences.prefs?.getString("BaseUrl")}/stream/${itemModel.inventoryItem?.category}/${itemModel.inventoryItem?.id}"), - ), - ); - }, - icon: const Icon(Icons.play_arrow), - label: const Text("Play"), - style: ElevatedButton.styleFrom( - padding: const EdgeInsets.symmetric( - vertical: 8, - ), - textStyle: const TextStyle( - fontSize: 18, - fontWeight: FontWeight.w400, - ), - backgroundColor: Colors.white, - foregroundColor: Colors.black, - ), - ), - ), + PlayButton( + itemModel: itemModel, ), const SizedBox(height: 8), Text( diff --git a/lib/views/player.dart b/lib/views/player.dart index 2c279aa..bb9a842 100644 --- a/lib/views/player.dart +++ b/lib/views/player.dart @@ -32,6 +32,13 @@ class _PlayerState extends State { ), ); + if (player.platform is NativePlayer) { + (player.platform as dynamic).setProperty( + 'http-header-fields', + 'Authentication=test', + ); + } + player.setSubtitleTrack(SubtitleTrack.no()); } diff --git a/lib/widgets/play_button.dart b/lib/widgets/play_button.dart new file mode 100644 index 0000000..7e4996b --- /dev/null +++ b/lib/widgets/play_button.dart @@ -0,0 +1,48 @@ +import 'package:flutter/material.dart'; +import 'package:open_media_server_app/apis/base_api.dart'; +import 'package:open_media_server_app/helpers/preferences.dart'; +import 'package:open_media_server_app/models/internal/grid_item_model.dart'; +import 'package:open_media_server_app/views/player.dart'; + +class PlayButton extends StatelessWidget { + const PlayButton({super.key, required this.itemModel}); + + final GridItemModel itemModel; + + @override + Widget build(BuildContext context) { + return Center( + child: SizedBox( + width: double.infinity, + height: 40, + child: ElevatedButton.icon( + onPressed: () async { + await BaseApi.getRefreshedHeaders(); + + await Navigator.push( + context, + MaterialPageRoute( + builder: (context) => PlayerView( + url: + "${Preferences.prefs?.getString("BaseUrl")}/stream/${itemModel.inventoryItem?.category}/${itemModel.inventoryItem?.id}"), + ), + ); + }, + icon: const Icon(Icons.play_arrow), + label: const Text("Play"), + style: ElevatedButton.styleFrom( + padding: const EdgeInsets.symmetric( + vertical: 8, + ), + textStyle: const TextStyle( + fontSize: 18, + fontWeight: FontWeight.w400, + ), + backgroundColor: Colors.white, + foregroundColor: Colors.black, + ), + ), + ), + ); + } +}