working media player on android
Co-authored-by: Copilot <copilot@github.com>
This commit is contained in:
+28
-6
@@ -1,14 +1,35 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:just_audio_background/just_audio_background.dart';
|
||||
|
||||
import 'streaming_audio_business_object.dart';
|
||||
|
||||
void main() {
|
||||
Future<void> main() async {
|
||||
WidgetsFlutterBinding.ensureInitialized();
|
||||
await JustAudioBackground.init(
|
||||
androidNotificationChannelId: 'com.kryzgoflutter.audio.channel',
|
||||
androidNotificationChannelName: 'KRYZ Audio Playback',
|
||||
androidNotificationOngoing: true,
|
||||
);
|
||||
|
||||
runApp(const MyApp());
|
||||
}
|
||||
|
||||
class MyApp extends StatelessWidget {
|
||||
class MyApp extends StatefulWidget {
|
||||
const MyApp({super.key});
|
||||
|
||||
@override
|
||||
State<MyApp> createState() => _MyAppState();
|
||||
}
|
||||
|
||||
class _MyAppState extends State<MyApp> {
|
||||
final StreamingAudioBusinessObject _audio = StreamingAudioBusinessObject();
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_audio.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return MaterialApp(
|
||||
@@ -16,21 +37,23 @@ class MyApp extends StatelessWidget {
|
||||
theme: ThemeData(
|
||||
colorScheme: ColorScheme.fromSeed(seedColor: Colors.blueGrey),
|
||||
),
|
||||
home: const MainPage(),
|
||||
home: MainPage(audio: _audio),
|
||||
debugShowCheckedModeBanner: false,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class MainPage extends StatefulWidget {
|
||||
const MainPage({super.key});
|
||||
const MainPage({super.key, required this.audio});
|
||||
|
||||
final StreamingAudioBusinessObject audio;
|
||||
|
||||
@override
|
||||
State<MainPage> createState() => _MainPageState();
|
||||
}
|
||||
|
||||
class _MainPageState extends State<MainPage> {
|
||||
final StreamingAudioBusinessObject _audio = StreamingAudioBusinessObject();
|
||||
StreamingAudioBusinessObject get _audio => widget.audio;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
@@ -59,7 +82,6 @@ class _MainPageState extends State<MainPage> {
|
||||
@override
|
||||
void dispose() {
|
||||
_audio.removeListener(_handleAudioStateChanged);
|
||||
_audio.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user