Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add audio playback on Linux #1511

Merged
merged 2 commits into from
Apr 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/flutter-linux-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
- name: Update apt-get
run: sudo apt-get update
- name: Install libraries
run: sudo apt-get install libgtk-3-dev cmake cmake-doc ninja-build libsecret-1-dev libjsoncpp-dev libsecret-1-0 sqlite3 libsqlite3-dev keybinder-3.0 network-manager
run: sudo apt-get install libgtk-3-dev cmake cmake-doc ninja-build libsecret-1-dev libjsoncpp-dev libsecret-1-0 sqlite3 libsqlite3-dev keybinder-3.0 network-manager mpv libmpv-dev
- name: Enable Linux Desktop
run: flutter config --enable-linux-desktop
- name: Flutter Doctor
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/flutter-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
- name: Update apt-get
run: sudo apt-get update
- name: Install libraries
run: sudo apt-get install network-manager
run: sudo apt-get install network-manager mpv libmpv-dev
- uses: actions/checkout@v3
- uses: subosito/flutter-action@v2
with:
Expand Down
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]
### Added:
- Audio playback on Linux

### Changed:
- Upgraded dependencies

## [0.8.330] - 2023-04-24
### Changed:
- Sync assistant styling
- Upgraded dependencies
Expand Down
24 changes: 12 additions & 12 deletions ios/Podfile.lock
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
PODS:
- audio_session (0.0.1):
- Flutter
- connectivity_plus (0.0.1):
- Flutter
- ReachabilitySwift
Expand Down Expand Up @@ -33,8 +31,6 @@ PODS:
- Flutter
- integration_test (0.0.1):
- Flutter
- just_audio (0.0.1):
- Flutter
- libwebp (1.2.4):
- libwebp/demux (= 1.2.4)
- libwebp/mux (= 1.2.4)
Expand All @@ -49,6 +45,10 @@ PODS:
- Mantle (2.2.0):
- Mantle/extobjc (= 2.2.0)
- Mantle/extobjc (2.2.0)
- media_kit_libs_ios_audio (1.0.4):
- Flutter
- media_kit_native_event_loop (1.0.0):
- Flutter
- MTBBarcodeScanner (5.0.11)
- package_info_plus (0.4.5):
- Flutter
Expand Down Expand Up @@ -103,7 +103,6 @@ PODS:
- Flutter

DEPENDENCIES:
- audio_session (from `.symlinks/plugins/audio_session/ios`)
- connectivity_plus (from `.symlinks/plugins/connectivity_plus/ios`)
- device_info_plus (from `.symlinks/plugins/device_info_plus/ios`)
- Flutter (from `Flutter`)
Expand All @@ -117,8 +116,9 @@ DEPENDENCIES:
- flutter_secure_storage (from `.symlinks/plugins/flutter_secure_storage/ios`)
- health (from `.symlinks/plugins/health/ios`)
- integration_test (from `.symlinks/plugins/integration_test/ios`)
- just_audio (from `.symlinks/plugins/just_audio/ios`)
- location (from `.symlinks/plugins/location/ios`)
- media_kit_libs_ios_audio (from `.symlinks/plugins/media_kit_libs_ios_audio/ios`)
- media_kit_native_event_loop (from `.symlinks/plugins/media_kit_native_event_loop/ios`)
- package_info_plus (from `.symlinks/plugins/package_info_plus/ios`)
- pasteboard (from `.symlinks/plugins/pasteboard/ios`)
- path_provider_foundation (from `.symlinks/plugins/path_provider_foundation/ios`)
Expand All @@ -145,8 +145,6 @@ SPEC REPOS:
- sqlite3

EXTERNAL SOURCES:
audio_session:
:path: ".symlinks/plugins/audio_session/ios"
connectivity_plus:
:path: ".symlinks/plugins/connectivity_plus/ios"
device_info_plus:
Expand All @@ -173,10 +171,12 @@ EXTERNAL SOURCES:
:path: ".symlinks/plugins/health/ios"
integration_test:
:path: ".symlinks/plugins/integration_test/ios"
just_audio:
:path: ".symlinks/plugins/just_audio/ios"
location:
:path: ".symlinks/plugins/location/ios"
media_kit_libs_ios_audio:
:path: ".symlinks/plugins/media_kit_libs_ios_audio/ios"
media_kit_native_event_loop:
:path: ".symlinks/plugins/media_kit_native_event_loop/ios"
package_info_plus:
:path: ".symlinks/plugins/package_info_plus/ios"
pasteboard:
Expand Down Expand Up @@ -205,7 +205,6 @@ EXTERNAL SOURCES:
:path: ".symlinks/plugins/video_player_avfoundation/ios"

SPEC CHECKSUMS:
audio_session: 4f3e461722055d21515cf3261b64c973c062f345
connectivity_plus: 413a8857dd5d9f1c399a39130850d02fe0feaf7e
device_info_plus: e5c5da33f982a436e103237c0c85f9031142abed
Flutter: f04841e97a9d0b0a8025694d0796dd46242b2854
Expand All @@ -220,10 +219,11 @@ SPEC CHECKSUMS:
FMDB: 2ce00b547f966261cd18927a3ddb07cb6f3db82a
health: 5a380c0f6c4f619535845992993964293962e99e
integration_test: a1e7d09bd98eca2fc37aefd79d4f41ad37bdbbe5
just_audio: baa7252489dbcf47a4c7cc9ca663e9661c99aafa
libwebp: f62cb61d0a484ba548448a4bd52aabf150ff6eef
location: 3a2eed4dd2fab25e7b7baf2a9efefe82b512d740
Mantle: c5aa8794a29a022dfbbfc9799af95f477a69b62d
media_kit_libs_ios_audio: 54c8c3556addbc15f3e8100306f5fa866c1233ab
media_kit_native_event_loop: 4aee6fad741e020d6935e204b8b1388bbd68beeb
MTBBarcodeScanner: f453b33c4b7dfe545d8c6484ed744d55671788cb
package_info_plus: 6c92f08e1f853dc01228d6f553146438dafcd14e
pasteboard: 982969ebaa7c78af3e6cc7761e8f5e77565d9ce0
Expand Down
26 changes: 10 additions & 16 deletions lib/blocs/audio/player_cubit.dart
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import 'package:bloc/bloc.dart';
import 'package:just_audio/just_audio.dart';
import 'package:lotti/blocs/audio/player_state.dart';
import 'package:lotti/classes/journal_entities.dart';
import 'package:lotti/database/logging_db.dart';
import 'package:lotti/get_it.dart';
import 'package:lotti/utils/audio_utils.dart';
import 'package:lotti/widgets/journal/entry_tools.dart';
import 'package:media_kit/media_kit.dart';

class AudioPlayerCubit extends Cubit<AudioPlayerState> {
AudioPlayerCubit()
Expand All @@ -18,15 +18,10 @@ class AudioPlayerCubit extends Cubit<AudioPlayerState> {
speed: 1,
),
) {
_audioPlayer.positionStream.listen(updateProgress);
_audioPlayer.playbackEventStream.listen((event) {
if (event.processingState == ProcessingState.completed) {
stopPlay();
}
});
_audioPlayer.streams.position.listen(updateProgress);
}

final AudioPlayer _audioPlayer = AudioPlayer();
final Player _audioPlayer = Player();
final LoggingDb _loggingDb = getIt<LoggingDb>();

void updateProgress(Duration duration) {
Expand All @@ -49,11 +44,9 @@ class AudioPlayerCubit extends Cubit<AudioPlayerState> {
audioNote: audioNote,
);
emit(newState);

final totalDuration = await _audioPlayer.setFilePath(localPath);
if (totalDuration != null) {
emit(newState.copyWith(totalDuration: totalDuration));
}
await _audioPlayer.open(Media(localPath));
final totalDuration = _audioPlayer.state.duration;
emit(newState.copyWith(totalDuration: totalDuration));
} catch (exception, stackTrace) {
_loggingDb.captureException(
exception,
Expand All @@ -65,7 +58,7 @@ class AudioPlayerCubit extends Cubit<AudioPlayerState> {

Future<void> play() async {
try {
await _audioPlayer.setSpeed(state.speed);
await _audioPlayer.setRate(state.speed);
await _audioPlayer.play();
await _audioPlayer.seek(state.pausedAt);
emit(state.copyWith(status: AudioPlayerStatus.playing));
Expand All @@ -80,7 +73,8 @@ class AudioPlayerCubit extends Cubit<AudioPlayerState> {

Future<void> stopPlay() async {
try {
await _audioPlayer.stop();
await _audioPlayer.pause();
await _audioPlayer.seek(Duration.zero);
emit(
state.copyWith(
status: AudioPlayerStatus.stopped,
Expand Down Expand Up @@ -116,7 +110,7 @@ class AudioPlayerCubit extends Cubit<AudioPlayerState> {

Future<void> setSpeed(double speed) async {
try {
await _audioPlayer.setSpeed(speed);
await _audioPlayer.setRate(speed);
emit(state.copyWith(speed: speed));
} catch (exception, stackTrace) {
_loggingDb.captureException(
Expand Down
2 changes: 2 additions & 0 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@ import 'package:lotti/database/settings_db.dart';
import 'package:lotti/get_it.dart';
import 'package:lotti/services/window_service.dart';
import 'package:lotti/sync/secure_storage.dart';
import 'package:media_kit/media_kit.dart';
import 'package:path_provider/path_provider.dart';
import 'package:timezone/data/latest.dart' as tz;
import 'package:window_manager/window_manager.dart';

Future<void> main() async {
WidgetsFlutterBinding.ensureInitialized();
MediaKit.ensureInitialized();

if (Platform.isMacOS) {
await windowManager.ensureInitialized();
Expand Down
4 changes: 4 additions & 0 deletions linux/flutter/generated_plugin_registrant.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <dynamic_color/dynamic_color_plugin.h>
#include <flutter_secure_storage_linux/flutter_secure_storage_linux_plugin.h>
#include <hotkey_manager/hotkey_manager_plugin.h>
#include <media_kit_libs_linux/media_kit_libs_linux_plugin.h>
#include <pasteboard/pasteboard_plugin.h>
#include <record_linux/record_linux_plugin.h>
#include <screen_retriever/screen_retriever_plugin.h>
Expand All @@ -26,6 +27,9 @@ void fl_register_plugins(FlPluginRegistry* registry) {
g_autoptr(FlPluginRegistrar) hotkey_manager_registrar =
fl_plugin_registry_get_registrar_for_plugin(registry, "HotkeyManagerPlugin");
hotkey_manager_plugin_register_with_registrar(hotkey_manager_registrar);
g_autoptr(FlPluginRegistrar) media_kit_libs_linux_registrar =
fl_plugin_registry_get_registrar_for_plugin(registry, "MediaKitLibsLinuxPlugin");
media_kit_libs_linux_plugin_register_with_registrar(media_kit_libs_linux_registrar);
g_autoptr(FlPluginRegistrar) pasteboard_registrar =
fl_plugin_registry_get_registrar_for_plugin(registry, "PasteboardPlugin");
pasteboard_plugin_register_with_registrar(pasteboard_registrar);
Expand Down
2 changes: 2 additions & 0 deletions linux/flutter/generated_plugins.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ list(APPEND FLUTTER_PLUGIN_LIST
dynamic_color
flutter_secure_storage_linux
hotkey_manager
media_kit_libs_linux
pasteboard
record_linux
screen_retriever
Expand All @@ -15,6 +16,7 @@ list(APPEND FLUTTER_PLUGIN_LIST
)

list(APPEND FLUTTER_FFI_PLUGIN_LIST
media_kit_native_event_loop
)

set(PLUGIN_BUNDLED_LIBRARIES)
Expand Down
6 changes: 2 additions & 4 deletions macos/Flutter/GeneratedPluginRegistrant.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,16 @@
import FlutterMacOS
import Foundation

import audio_session
import connectivity_plus
import device_info_plus
import dynamic_color
import flutter_local_notifications
import flutter_native_timezone
import flutter_secure_storage_macos
import hotkey_manager
import just_audio
import location
import macos_ui
import media_kit_libs_macos_audio
import package_info_plus
import pasteboard
import path_provider_foundation
Expand All @@ -30,17 +29,16 @@ import url_launcher_macos
import window_manager

func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) {
AudioSessionPlugin.register(with: registry.registrar(forPlugin: "AudioSessionPlugin"))
ConnectivityPlugin.register(with: registry.registrar(forPlugin: "ConnectivityPlugin"))
DeviceInfoPlusMacosPlugin.register(with: registry.registrar(forPlugin: "DeviceInfoPlusMacosPlugin"))
DynamicColorPlugin.register(with: registry.registrar(forPlugin: "DynamicColorPlugin"))
FlutterLocalNotificationsPlugin.register(with: registry.registrar(forPlugin: "FlutterLocalNotificationsPlugin"))
FlutterNativeTimezonePlugin.register(with: registry.registrar(forPlugin: "FlutterNativeTimezonePlugin"))
FlutterSecureStoragePlugin.register(with: registry.registrar(forPlugin: "FlutterSecureStoragePlugin"))
HotkeyManagerPlugin.register(with: registry.registrar(forPlugin: "HotkeyManagerPlugin"))
JustAudioPlugin.register(with: registry.registrar(forPlugin: "JustAudioPlugin"))
LocationPlugin.register(with: registry.registrar(forPlugin: "LocationPlugin"))
MacOSUiPlugin.register(with: registry.registrar(forPlugin: "MacOSUiPlugin"))
MediaKitLibsMacosAudioPlugin.register(with: registry.registrar(forPlugin: "MediaKitLibsMacosAudioPlugin"))
FLTPackageInfoPlusPlugin.register(with: registry.registrar(forPlugin: "FLTPackageInfoPlusPlugin"))
PasteboardPlugin.register(with: registry.registrar(forPlugin: "PasteboardPlugin"))
PathProviderPlugin.register(with: registry.registrar(forPlugin: "PathProviderPlugin"))
Expand Down
2 changes: 1 addition & 1 deletion macos/Podfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
platform :osx, '10.15'
platform :osx, '11.0'
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We're reducing the minimum supported macOS version (if it matters) to improve backwards compatibility:
media-kit/libmpv-darwin-build#7


# CocoaPods analytics sends network stats synchronously affecting flutter build latency.
ENV['COCOAPODS_DISABLE_STATS'] = 'true'
Expand Down
26 changes: 13 additions & 13 deletions macos/Podfile.lock
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
PODS:
- audio_session (0.0.1):
- FlutterMacOS
- connectivity_plus (0.0.1):
- FlutterMacOS
- ReachabilitySwift
Expand All @@ -22,12 +20,14 @@ PODS:
- hotkey_manager (0.0.1):
- FlutterMacOS
- HotKey
- just_audio (0.0.1):
- FlutterMacOS
- location (0.0.1):
- FlutterMacOS
- macos_ui (0.1.0):
- FlutterMacOS
- media_kit_libs_macos_audio (1.0.4):
- FlutterMacOS
- media_kit_native_event_loop (1.0.0):
- FlutterMacOS
- package_info_plus (0.0.1):
- FlutterMacOS
- pasteboard (0.0.1):
Expand Down Expand Up @@ -72,7 +72,6 @@ PODS:
- FlutterMacOS

DEPENDENCIES:
- audio_session (from `Flutter/ephemeral/.symlinks/plugins/audio_session/macos`)
- connectivity_plus (from `Flutter/ephemeral/.symlinks/plugins/connectivity_plus/macos`)
- device_info_plus (from `Flutter/ephemeral/.symlinks/plugins/device_info_plus/macos`)
- dynamic_color (from `Flutter/ephemeral/.symlinks/plugins/dynamic_color/macos`)
Expand All @@ -81,9 +80,10 @@ DEPENDENCIES:
- flutter_secure_storage_macos (from `Flutter/ephemeral/.symlinks/plugins/flutter_secure_storage_macos/macos`)
- FlutterMacOS (from `Flutter/ephemeral`)
- hotkey_manager (from `Flutter/ephemeral/.symlinks/plugins/hotkey_manager/macos`)
- just_audio (from `Flutter/ephemeral/.symlinks/plugins/just_audio/macos`)
- location (from `Flutter/ephemeral/.symlinks/plugins/location/macos`)
- macos_ui (from `Flutter/ephemeral/.symlinks/plugins/macos_ui/macos`)
- media_kit_libs_macos_audio (from `Flutter/ephemeral/.symlinks/plugins/media_kit_libs_macos_audio/macos`)
- media_kit_native_event_loop (from `Flutter/ephemeral/.symlinks/plugins/media_kit_native_event_loop/macos`)
- package_info_plus (from `Flutter/ephemeral/.symlinks/plugins/package_info_plus/macos`)
- pasteboard (from `Flutter/ephemeral/.symlinks/plugins/pasteboard/macos`)
- path_provider_foundation (from `Flutter/ephemeral/.symlinks/plugins/path_provider_foundation/macos`)
Expand All @@ -105,8 +105,6 @@ SPEC REPOS:
- sqlite3

EXTERNAL SOURCES:
audio_session:
:path: Flutter/ephemeral/.symlinks/plugins/audio_session/macos
connectivity_plus:
:path: Flutter/ephemeral/.symlinks/plugins/connectivity_plus/macos
device_info_plus:
Expand All @@ -123,12 +121,14 @@ EXTERNAL SOURCES:
:path: Flutter/ephemeral
hotkey_manager:
:path: Flutter/ephemeral/.symlinks/plugins/hotkey_manager/macos
just_audio:
:path: Flutter/ephemeral/.symlinks/plugins/just_audio/macos
location:
:path: Flutter/ephemeral/.symlinks/plugins/location/macos
macos_ui:
:path: Flutter/ephemeral/.symlinks/plugins/macos_ui/macos
media_kit_libs_macos_audio:
:path: Flutter/ephemeral/.symlinks/plugins/media_kit_libs_macos_audio/macos
media_kit_native_event_loop:
:path: Flutter/ephemeral/.symlinks/plugins/media_kit_native_event_loop/macos
package_info_plus:
:path: Flutter/ephemeral/.symlinks/plugins/package_info_plus/macos
pasteboard:
Expand All @@ -155,7 +155,6 @@ EXTERNAL SOURCES:
:path: Flutter/ephemeral/.symlinks/plugins/window_manager/macos

SPEC CHECKSUMS:
audio_session: dea1f41890dbf1718f04a56f1d6150fd50039b72
connectivity_plus: 18d3c32514c886e046de60e9c13895109866c747
device_info_plus: 5401765fde0b8d062a2f8eb65510fb17e77cf07f
dynamic_color: 2eaa27267de1ca20d879fbd6e01259773fb1670f
Expand All @@ -166,9 +165,10 @@ SPEC CHECKSUMS:
FMDB: 2ce00b547f966261cd18927a3ddb07cb6f3db82a
HotKey: ad59450195936c10992438c4210f673de5aee43e
hotkey_manager: ad673457691f4d39e481be04a61da2ae07d81c62
just_audio: 9b67ca7b97c61cfc9784ea23cd8cc55eb226d489
location: 7cdb0665bd6577d382b0a343acdadbcb7f964775
macos_ui: 6229a8922cd97bafb7d9636c8eb8dfb0744183ca
media_kit_libs_macos_audio: f4a889541a2317614c98d2ad3f08e358accaa39b
media_kit_native_event_loop: 81f3d1888a9bd283e5416276fd5716aa331d1751
package_info_plus: 02d7a575e80f194102bef286361c6c326e4c29ce
pasteboard: 9b69dba6fedbb04866be632205d532fe2f6b1d99
path_provider_foundation: c68054786f1b4f3343858c1e1d0caaded73f0be9
Expand All @@ -184,6 +184,6 @@ SPEC CHECKSUMS:
url_launcher_macos: 5335912b679c073563f29d89d33d10d459f95451
window_manager: 3a1844359a6295ab1e47659b1a777e36773cd6e8

PODFILE CHECKSUM: 9323785527ecef788ef9f2b3408155b4bb242a79
PODFILE CHECKSUM: 0d353b18ff12f5d7cf17ff0e726ed751fc815029

COCOAPODS: 1.12.0
Loading