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 a "Use Vorbis" switch #151

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
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
34 changes: 34 additions & 0 deletions lib/components/TranscodingSettingsScreen/VorbisSwitch.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import 'package:flutter/material.dart';
import 'package:hive/hive.dart';

import '../../services/FinampSettingsHelper.dart';
import '../../models/FinampModels.dart';

class VorbisSwitch extends StatelessWidget {
const VorbisSwitch({Key? key}) : super(key: key);

@override
Widget build(BuildContext context) {
return ValueListenableBuilder<Box<FinampSettings>>(
valueListenable: FinampSettingsHelper.finampSettingsListener,
builder: (context, box, child) {
bool? useVorbis = box.get("FinampSettings")?.useVorbis;

return SwitchListTile(
title: const Text("Use Vorbis Codec"),
subtitle: const Text(
"If enabled, music streams will be transcoded to Vorbis and not AAC by the server."),
value: useVorbis ?? false,
onChanged: useVorbis == null
? null
: (value) {
FinampSettings finampSettingsTemp =
box.get("FinampSettings")!;
finampSettingsTemp.useVorbis = value;
box.put("FinampSettings", finampSettingsTemp);
},
);
},
);
}
}
7 changes: 7 additions & 0 deletions lib/models/FinampModels.dart
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ const _contentGridViewCrossAxisCountPortrait = 2;
const _contentGridViewCrossAxisCountLandscape = 3;
const _showTextOnGridView = true;
const _sleepTimerSeconds = 1800; // 30 Minutes
const _useVorbis = false;

@HiveType(typeId: 28)
class FinampSettings {
Expand All @@ -68,6 +69,7 @@ class FinampSettings {
_contentGridViewCrossAxisCountLandscape,
this.showTextOnGridView = _showTextOnGridView,
this.sleepTimerSeconds = _sleepTimerSeconds,
this.useVorbis = _useVorbis,
});

@HiveField(0)
Expand Down Expand Up @@ -123,6 +125,11 @@ class FinampSettings {
@HiveField(14, defaultValue: _sleepTimerSeconds)
int sleepTimerSeconds;

/// Whether or not to request Vorbis as the transcoding codec.
/// If false, AAC will be used.
@HiveField(15, defaultValue: _useVorbis)
bool useVorbis;

static Future<FinampSettings> create() async {
Directory internalSongDir = await getInternalSongDir();
return FinampSettings(
Expand Down
7 changes: 5 additions & 2 deletions lib/models/FinampModels.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 4 additions & 8 deletions lib/screens/TranscodingSettingsScreen.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import 'dart:io';

import 'package:flutter/material.dart';

import '../components/TranscodingSettingsScreen/TranscodeSwitch.dart';
import '../components/TranscodingSettingsScreen/BitrateSelector.dart';
import '../components/TranscodingSettingsScreen/VorbisSwitch.dart';

class TranscodingSettingsScreen extends StatelessWidget {
const TranscodingSettingsScreen({Key? key}) : super(key: key);
Expand All @@ -17,14 +20,7 @@ class TranscodingSettingsScreen extends StatelessWidget {
children: [
const TranscodeSwitch(),
const BitrateSelector(),
Padding(
padding: const EdgeInsets.all(8.0),
child: Text(
"Jellyfin uses AAC for transcoding.",
style: Theme.of(context).textTheme.caption,
textAlign: TextAlign.center,
),
),
if (!(Platform.isIOS || Platform.isMacOS)) const VorbisSwitch(),
],
),
),
Expand Down
1 change: 1 addition & 0 deletions lib/services/AudioServiceHelper.dart
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,7 @@ class AudioServiceHelper {
"shouldTranscode": FinampSettingsHelper.finampSettings.shouldTranscode,
"downloadedSongJson": (await _getDownloadedSong(item.id))?.toJson(),
"isOffline": FinampSettingsHelper.finampSettings.isOffline,
"useVorbis": FinampSettingsHelper.finampSettings.useVorbis,
// TODO: Maybe add transcoding bitrate here?
},
rating: Rating.newHeartRating(item.userData?.isFavorite ?? false),
Expand Down
7 changes: 4 additions & 3 deletions lib/services/MusicPlayerBackgroundTask.dart
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,8 @@ class MusicPlayerBackgroundTask extends BaseAudioHandler {
return Future.error(
"Offline mode enabled but downloaded song not found.");
} else {
if (mediaItem.extras!["shouldTranscode"] == true) {
if (mediaItem.extras!["shouldTranscode"] == true &&
mediaItem.extras!["useVorbis"] == false) {
return HlsAudioSource(await _songUri(mediaItem));
} else {
return AudioSource.uri(await _songUri(mediaItem));
Expand Down Expand Up @@ -524,10 +525,10 @@ class MusicPlayerBackgroundTask extends BaseAudioHandler {
"MaxStreamingBitrate": mediaItem.extras!["shouldTranscode"]
? FinampSettingsHelper.finampSettings.transcodeBitrate.toString()
: "999999999",
"AudioCodec": "aac",
"AudioCodec": mediaItem.extras!["useVorbis"] ? "vorbis" : "aac",
"TranscodingContainer": "ts",
"TranscodingProtocol":
mediaItem.extras!["shouldTranscode"] ? "hls" : "http",
mediaItem.extras!["shouldTranscode"] ? (mediaItem.extras!["useVorbis"] ? "http" : "hls") : "http",
"ApiKey": _jellyfinApiData.currentUser!.accessToken,
},
);
Expand Down