Skip to content

Commit

Permalink
✨ Refresh token on press play if needed
Browse files Browse the repository at this point in the history
  • Loading branch information
LNA-DEV committed Nov 3, 2024
1 parent 1427f92 commit 0f48740
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 64 deletions.
35 changes: 3 additions & 32 deletions lib/views/detail_views/episode_detail.dart
Original file line number Diff line number Diff line change
@@ -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({
Expand Down Expand Up @@ -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,
Expand Down
35 changes: 3 additions & 32 deletions lib/views/detail_views/movie_detail.dart
Original file line number Diff line number Diff line change
@@ -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({
Expand Down Expand Up @@ -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(
Expand Down
7 changes: 7 additions & 0 deletions lib/views/player.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,13 @@ class _PlayerState extends State<PlayerView> {
),
);

if (player.platform is NativePlayer) {
(player.platform as dynamic).setProperty(
'http-header-fields',
'Authentication=test',
);
}

player.setSubtitleTrack(SubtitleTrack.no());
}

Expand Down
48 changes: 48 additions & 0 deletions lib/widgets/play_button.dart
Original file line number Diff line number Diff line change
@@ -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,
),
),
),
);
}
}

0 comments on commit 0f48740

Please sign in to comment.