-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #72 from bitmovin/feature/add-background-playback-…
…example Add flutter like background playback example
- Loading branch information
Showing
9 changed files
with
152 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
import 'dart:io'; | ||
|
||
import 'package:audio_session/audio_session.dart'; | ||
import 'package:bitmovin_player/bitmovin_player.dart'; | ||
import 'package:bitmovin_player_example/controls.dart'; | ||
import 'package:bitmovin_player_example/env/env.dart'; | ||
import 'package:flutter/material.dart'; | ||
|
||
/// This example showcases how to achieve background playback with the | ||
/// Bitmovin Player using the `audio_session` package. | ||
/// https://pub.dev/packages/audio_session | ||
class BackgroundPlayback extends StatefulWidget { | ||
const BackgroundPlayback({super.key}); | ||
static String routeName = 'BackgroundPlayback'; | ||
|
||
@override | ||
State<BackgroundPlayback> createState() => _BackgroundPlaybackState(); | ||
} | ||
|
||
class _BackgroundPlaybackState extends State<BackgroundPlayback> { | ||
final _sourceConfig = SourceConfig( | ||
url: Platform.isAndroid | ||
? 'https://bitmovin-a.akamaihd.net/content/MI201109210084_1/mpds/f08e80da-bf1d-4e3d-8899-f0f6155f6efa.mpd' | ||
: 'https://bitmovin-a.akamaihd.net/content/MI201109210084_1/m3u8s/f08e80da-bf1d-4e3d-8899-f0f6155f6efa.m3u8', | ||
type: Platform.isAndroid ? SourceType.dash : SourceType.hls, | ||
); | ||
final _player = Player( | ||
config: const PlayerConfig( | ||
key: Env.bitmovinPlayerLicenseKey, | ||
playbackConfig: PlaybackConfig( | ||
isAutoplayEnabled: true, | ||
isBackgroundPlaybackEnabled: true, | ||
), | ||
remoteControlConfig: RemoteControlConfig(isCastEnabled: false), | ||
), | ||
); | ||
|
||
@override | ||
void initState() { | ||
setupAudioSession(); | ||
|
||
_player.loadSourceConfig(_sourceConfig); | ||
super.initState(); | ||
} | ||
|
||
Future<void> setupAudioSession() async { | ||
final session = await AudioSession.instance; | ||
await session.configure(const AudioSessionConfiguration.music()); | ||
} | ||
|
||
@override | ||
void dispose() { | ||
_player.dispose(); | ||
super.dispose(); | ||
} | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return Scaffold( | ||
appBar: AppBar( | ||
title: const Text('Background Playback'), | ||
), | ||
body: Column( | ||
children: [ | ||
SizedBox.fromSize( | ||
size: const Size.fromHeight(226), | ||
child: PlayerView( | ||
player: _player, | ||
), | ||
), | ||
Container( | ||
margin: const EdgeInsets.only(top: 5), | ||
child: Controls( | ||
onLoadPressed: () => _player.loadSourceConfig(_sourceConfig), | ||
onPlayPressed: _player.play, | ||
onPausePressed: _player.pause, | ||
onMutePressed: _player.mute, | ||
onUnmutePressed: _player.unmute, | ||
onSkipForwardPressed: () async => | ||
_player.seek(await _player.currentTime + 10), | ||
onSkipBackwardPressed: () async => | ||
_player.seek(await _player.currentTime - 10), | ||
), | ||
), | ||
], | ||
), | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters