kd_youtube_background_audio 0.0.6
kd_youtube_background_audio: ^0.0.6 copied to clipboard
A robust Flutter package to reliably extract and play YouTube audio in the background. Handles muxed streams, Doze mode, and web CORS proxies.
example/lib/main.dart
import 'package:flutter/material.dart';
import 'package:audio_service/audio_service.dart';
import 'package:kd_youtube_background_audio/kd_youtube_background_audio.dart';
Future<void> main() async {
WidgetsFlutterBinding.ensureInitialized();
final audioHandler = await AudioService.init<KdYoutubeAudioHandler>(
builder: () => KdYoutubeAudioHandler(),
config: const AudioServiceConfig(
androidNotificationChannelId: 'com.example.audio',
androidNotificationChannelName: 'Audio playback',
),
);
runApp(MyApp(audioHandler: audioHandler));
}
class MyApp extends StatelessWidget {
final KdYoutubeAudioHandler audioHandler;
const MyApp({super.key, required this.audioHandler});
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(title: const Text('KD YouTube Audio')),
body: Center(
child: ElevatedButton(
onPressed: () async {
await audioHandler.playFromYoutube(
videoId: 'dQw4w9WgXcQ',
useMuxed: true,
);
},
child: const Text('Play Audio'),
),
),
),
);
}
}