mirror of
https://gitlab.com/comunic/comunicmobile
synced 2024-11-25 22:39:22 +00:00
Integrate an audio player in the application
This commit is contained in:
parent
8f2574a555
commit
3518594eea
@ -4,4 +4,7 @@
|
|||||||
to allow setting breakpoints, to provide hot reload, etc.
|
to allow setting breakpoints, to provide hot reload, etc.
|
||||||
-->
|
-->
|
||||||
<uses-permission android:name="android.permission.INTERNET"/>
|
<uses-permission android:name="android.permission.INTERNET"/>
|
||||||
|
|
||||||
|
<!-- Use clear connection in dev mode -->
|
||||||
|
<application android:usesCleartextTraffic="true" />
|
||||||
</manifest>
|
</manifest>
|
||||||
|
82
lib/ui/dialogs/audio_player_dialog.dart
Normal file
82
lib/ui/dialogs/audio_player_dialog.dart
Normal file
@ -0,0 +1,82 @@
|
|||||||
|
import 'package:chewie_audio/chewie_audio.dart';
|
||||||
|
import 'package:comunic/ui/widgets/async_screen_widget.dart';
|
||||||
|
import 'package:comunic/utils/intl_utils.dart';
|
||||||
|
import 'package:flutter/cupertino.dart';
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:video_player/video_player.dart';
|
||||||
|
|
||||||
|
/// Audio player dialog
|
||||||
|
///
|
||||||
|
/// @author Pierre Hubert
|
||||||
|
|
||||||
|
/// Show audio player dialog
|
||||||
|
Future<void> showAudioPlayerDialog(BuildContext context, String url) async {
|
||||||
|
showDialog(context: context, builder: (c) => _AudioPlayerDialog(url: url));
|
||||||
|
}
|
||||||
|
|
||||||
|
class _AudioPlayerDialog extends StatefulWidget {
|
||||||
|
final String url;
|
||||||
|
|
||||||
|
const _AudioPlayerDialog({
|
||||||
|
Key key,
|
||||||
|
@required this.url,
|
||||||
|
}) : assert(url != null),
|
||||||
|
super(key: key);
|
||||||
|
|
||||||
|
@override
|
||||||
|
__AudioPlayerDialogState createState() => __AudioPlayerDialogState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class __AudioPlayerDialogState extends State<_AudioPlayerDialog> {
|
||||||
|
VideoPlayerController _videoPlayerController;
|
||||||
|
ChewieAudioController _chewieAudioController;
|
||||||
|
|
||||||
|
Future<void> _initialize() async {
|
||||||
|
_videoPlayerController = VideoPlayerController.network(widget.url);
|
||||||
|
|
||||||
|
await _videoPlayerController.initialize();
|
||||||
|
|
||||||
|
_chewieAudioController = ChewieAudioController(
|
||||||
|
videoPlayerController: _videoPlayerController,
|
||||||
|
autoPlay: true,
|
||||||
|
looping: false,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
void _closeDialog() {
|
||||||
|
Navigator.pop(context);
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void dispose() {
|
||||||
|
if (_videoPlayerController != null) _videoPlayerController.dispose();
|
||||||
|
if (_chewieAudioController != null) _chewieAudioController.dispose();
|
||||||
|
super.dispose();
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return AlertDialog(
|
||||||
|
title: Text(tr("Audio Player")),
|
||||||
|
content: _buildContent(),
|
||||||
|
actions: [
|
||||||
|
MaterialButton(
|
||||||
|
onPressed: _closeDialog,
|
||||||
|
child: Text(tr("Close").toUpperCase()),
|
||||||
|
)
|
||||||
|
],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Widget _buildContent() => ConstrainedBox(
|
||||||
|
constraints: BoxConstraints(maxHeight: 300, maxWidth: 500),
|
||||||
|
child: AsyncScreenWidget(
|
||||||
|
onReload: _initialize,
|
||||||
|
onBuild: _buildReadyContent,
|
||||||
|
errorMessage: tr("Failed to initialize audio player!"),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
Widget _buildReadyContent() =>
|
||||||
|
ChewieAudio(controller: _chewieAudioController);
|
||||||
|
}
|
@ -2,6 +2,7 @@
|
|||||||
///
|
///
|
||||||
/// @author Pierre Hubert
|
/// @author Pierre Hubert
|
||||||
import 'package:comunic/models/conversation_message.dart';
|
import 'package:comunic/models/conversation_message.dart';
|
||||||
|
import 'package:comunic/ui/dialogs/audio_player_dialog.dart';
|
||||||
import 'package:comunic/ui/widgets/network_image_widget.dart';
|
import 'package:comunic/ui/widgets/network_image_widget.dart';
|
||||||
import 'package:filesize/filesize.dart';
|
import 'package:filesize/filesize.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
@ -47,7 +48,7 @@ class _ConversationFileWidgetState extends State<ConversationFileWidget> {
|
|||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
// The file is not downloadable, we open it in the browser
|
// We open it in the browser
|
||||||
default:
|
default:
|
||||||
return Container(
|
return Container(
|
||||||
color: widget.defaultBackgroundColor,
|
color: widget.defaultBackgroundColor,
|
||||||
@ -69,11 +70,22 @@ class _ConversationFileWidgetState extends State<ConversationFileWidget> {
|
|||||||
Spacer(flex: 2),
|
Spacer(flex: 2),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
onPressed: () => launch(file.url),
|
onPressed: _openFile,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void _openFile() {
|
||||||
|
switch (file.fileType) {
|
||||||
|
case ConversationMessageFileType.AUDIO:
|
||||||
|
showAudioPlayerDialog(context, file.url);
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
launch(file.url);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
30
pubspec.lock
30
pubspec.lock
@ -50,6 +50,13 @@ packages:
|
|||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "1.2.0-nullsafety.1"
|
version: "1.2.0-nullsafety.1"
|
||||||
|
chewie_audio:
|
||||||
|
dependency: "direct main"
|
||||||
|
description:
|
||||||
|
name: chewie_audio
|
||||||
|
url: "https://pub.dartlang.org"
|
||||||
|
source: hosted
|
||||||
|
version: "1.1.2"
|
||||||
clipboard:
|
clipboard:
|
||||||
dependency: "direct main"
|
dependency: "direct main"
|
||||||
description:
|
description:
|
||||||
@ -126,7 +133,7 @@ packages:
|
|||||||
name: cupertino_icons
|
name: cupertino_icons
|
||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "0.1.3"
|
version: "1.0.0"
|
||||||
dio:
|
dio:
|
||||||
dependency: "direct main"
|
dependency: "direct main"
|
||||||
description:
|
description:
|
||||||
@ -651,6 +658,27 @@ packages:
|
|||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "1.2.0"
|
version: "1.2.0"
|
||||||
|
video_player:
|
||||||
|
dependency: "direct main"
|
||||||
|
description:
|
||||||
|
name: video_player
|
||||||
|
url: "https://pub.dartlang.org"
|
||||||
|
source: hosted
|
||||||
|
version: "1.0.1"
|
||||||
|
video_player_platform_interface:
|
||||||
|
dependency: transitive
|
||||||
|
description:
|
||||||
|
name: video_player_platform_interface
|
||||||
|
url: "https://pub.dartlang.org"
|
||||||
|
source: hosted
|
||||||
|
version: "2.2.0"
|
||||||
|
video_player_web:
|
||||||
|
dependency: transitive
|
||||||
|
description:
|
||||||
|
name: video_player_web
|
||||||
|
url: "https://pub.dartlang.org"
|
||||||
|
source: hosted
|
||||||
|
version: "0.1.4+1"
|
||||||
wakelock:
|
wakelock:
|
||||||
dependency: "direct main"
|
dependency: "direct main"
|
||||||
description:
|
description:
|
||||||
|
@ -22,7 +22,7 @@ dependencies:
|
|||||||
|
|
||||||
# The following adds the Cupertino Icons font to your application.
|
# The following adds the Cupertino Icons font to your application.
|
||||||
# Use with the CupertinoIcons class for iOS style icons.
|
# Use with the CupertinoIcons class for iOS style icons.
|
||||||
cupertino_icons: ^0.1.3
|
cupertino_icons: ^1.0.0
|
||||||
|
|
||||||
# Preferences are useful for a lot of things (ex: login tokens)
|
# Preferences are useful for a lot of things (ex: login tokens)
|
||||||
shared_preferences: ^0.5.6+3
|
shared_preferences: ^0.5.6+3
|
||||||
@ -103,6 +103,10 @@ dependencies:
|
|||||||
# Image manager
|
# Image manager
|
||||||
image: ^2.1.19
|
image: ^2.1.19
|
||||||
|
|
||||||
|
# Video / Audio player
|
||||||
|
video_player: ^1.0.1
|
||||||
|
chewie_audio: ^1.1.2
|
||||||
|
|
||||||
dev_dependencies:
|
dev_dependencies:
|
||||||
flutter_test:
|
flutter_test:
|
||||||
sdk: flutter
|
sdk: flutter
|
||||||
|
Loading…
Reference in New Issue
Block a user