Skip to content

Commit

Permalink
chore: few tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
MSOB7YY committed Oct 16, 2023
1 parent 6d43c26 commit 55cf7f7
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 14 deletions.
16 changes: 9 additions & 7 deletions lib/controller/audio_handler.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import 'package:get/get_rx/src/rx_types/rx_types.dart';
import 'package:get/get_utils/src/extensions/num_extensions.dart';
import 'package:just_audio/just_audio.dart';
import 'package:newpipeextractor_dart/newpipeextractor_dart.dart';
import 'package:permission_handler/permission_handler.dart';
import 'package:playlist_manager/module/playlist_id.dart';

import 'package:namida/class/audio_cache_detail.dart';
Expand All @@ -31,6 +32,7 @@ import 'package:namida/core/constants.dart';
import 'package:namida/core/enums.dart';
import 'package:namida/core/extensions.dart';
import 'package:namida/core/namida_converter_ext.dart';
import 'package:namida/main.dart';
import 'package:namida/ui/dialogs/common_dialogs.dart';
import 'package:namida/youtube/class/youtube_id.dart';
import 'package:namida/youtube/controller/youtube_controller.dart';
Expand Down Expand Up @@ -86,7 +88,7 @@ class NamidaAudioVideoHandler<Q extends Playable> extends BasicAudioHandler<Q> {
/// Milliseconds should be awaited before playing video.
int get _videoPositionSeekDelayMS => 500;

Completer<void>? _audioShouldBeLoading;
// Completer<void>? _audioShouldBeLoading;

Future<void> setAudioOnlyPlayback(bool audioOnly) async {
_isAudioOnlyPlayback = audioOnly;
Expand All @@ -100,7 +102,7 @@ class NamidaAudioVideoHandler<Q extends Playable> extends BasicAudioHandler<Q> {

Future<void> _waitForAllBuffers() async {
await waitTillAudioLoaded;
await _audioShouldBeLoading?.future;
// await _audioShouldBeLoading?.future;
await VideoController.vcontroller.waitTillBufferingComplete;
await bufferingCompleter?.future;
}
Expand Down Expand Up @@ -141,7 +143,7 @@ class NamidaAudioVideoHandler<Q extends Playable> extends BasicAudioHandler<Q> {

Future<void> toggleVideoPlay() async {
await _waitForAllBuffers();
await _audioShouldBeLoading?.future;
// await _audioShouldBeLoading?.future;
await VideoController.vcontroller.seek(currentPositionMS.milliseconds);
if (isPlaying) {
await VideoController.vcontroller.play();
Expand All @@ -157,7 +159,7 @@ class NamidaAudioVideoHandler<Q extends Playable> extends BasicAudioHandler<Q> {

Future<void> _playAudioThenVideo() async {
onPlayRaw();
await _audioShouldBeLoading?.future;
// await _audioShouldBeLoading?.future;
await Future.delayed(Duration(milliseconds: _videoPositionSeekDelayMS.abs()));
if (isPlaying) {
await VideoController.vcontroller.play();
Expand Down Expand Up @@ -301,7 +303,7 @@ class NamidaAudioVideoHandler<Q extends Playable> extends BasicAudioHandler<Q> {
@override
FutureOr<void> beforePlaying() async {
super.beforePlaying(); // saving last position.
_audioShouldBeLoading ??= Completer<void>();
// _audioShouldBeLoading ??= Completer<void>();
NamidaNavigator.inst.popAllMenus();
ScrollSearchController.inst.unfocusKeyboard();

Expand Down Expand Up @@ -1168,7 +1170,7 @@ class NamidaAudioVideoHandler<Q extends Playable> extends BasicAudioHandler<Q> {

@override
void onBufferOrLoadStart() {
_audioShouldBeLoading ??= Completer<void>();
// _audioShouldBeLoading ??= Completer<void>();
if (isPlaying) {
VideoController.vcontroller.pause();
}
Expand All @@ -1177,7 +1179,7 @@ class NamidaAudioVideoHandler<Q extends Playable> extends BasicAudioHandler<Q> {
@override
void onBufferOrLoadEnd() async {
await waitTillAudioLoaded;
_audioShouldBeLoading?.completeIfWasnt();
// _audioShouldBeLoading?.completeIfWasnt();
if (isPlaying) {
VideoController.vcontroller.play();
}
Expand Down
9 changes: 6 additions & 3 deletions lib/controller/indexer_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:get/get.dart';
import 'package:path/path.dart' as p;
import 'package:system_info2/system_info2.dart';

import 'package:namida/class/folder.dart';
import 'package:namida/class/split_config.dart';
Expand Down Expand Up @@ -845,14 +846,16 @@ class Indexer {

currentTrackPathBeingExtracted.value = '';
final chunkExtractList = <String>[];
final freeMemory = SysInfo.getFreePhysicalMemory();
final chunkSize = (freeMemory ~/ 4).clamp(8, 128);
if (audioFiles.isNotEmpty) {
// -- Extracting All Metadata
for (final trackPath in audioFiles) {
// breaks the loop if another indexing session has been started
if (_cancelableIndexingCompleter[cancelTokenTime]?.isCompleted == true) break;

printy(trackPath);
currentTrackPathBeingExtracted.value = trackPath;
// currentTrackPathBeingExtracted.value = trackPath;

/// skip duplicated tracks according to filename
if (prevDuplicated) {
Expand All @@ -862,7 +865,7 @@ class Indexer {
}
}

if (chunkExtractList.isNotEmpty && chunkExtractList.length % 24 == 0) {
if (chunkExtractList.isNotEmpty && chunkExtractList.length % chunkSize == 0) {
await extractOneTrack(
tracksPath: chunkExtractList,
minDur: minDur,
Expand All @@ -876,7 +879,7 @@ class Indexer {

chunkExtractList.add(trackPath);
}
// -- if there were any items left (length < 24)
// -- if there were any items left (length < chunkSize)
await extractOneTrack(
tracksPath: chunkExtractList,
minDur: minDur,
Expand Down
19 changes: 15 additions & 4 deletions lib/ui/widgets/artwork.dart
Original file line number Diff line number Diff line change
Expand Up @@ -73,20 +73,31 @@ class ArtworkWidget extends StatefulWidget {
}

class _ArtworkWidgetState extends State<ArtworkWidget> {
late DisposableBuildContext<_ArtworkWidgetState> _disposableContext;
@override
void initState() {
super.initState();
_disposableContext = DisposableBuildContext<_ArtworkWidgetState>(this);
}

@override
void dispose() {
_disposableContext.dispose();
super.dispose();
}

@override
Widget build(BuildContext context) {
final imagePath = widget.path;
final realWidthAndHeight = widget.forceSquared ? context.width : null;

int? finalCache;
if (widget.compressed) {
if (widget.compressed || widget.useTrackTileCacheHeight) {
final pixelRatio = context.mediaQuery.devicePixelRatio;
final cacheMultiplier = (pixelRatio * settings.artworkCacheHeightMultiplier.value).round();
finalCache = widget.useTrackTileCacheHeight ? 60 * cacheMultiplier : widget.cacheHeight * cacheMultiplier;
}

final c = DisposableBuildContext<_ArtworkWidgetState>(this);

final borderR = widget.isCircle || settings.borderRadiusMultiplier.value == 0 ? null : BorderRadius.circular(widget.borderRadius.multipliedRadius);
final shape = widget.isCircle ? BoxShape.circle : BoxShape.rectangle;

Expand Down Expand Up @@ -149,7 +160,7 @@ class _ArtworkWidgetState extends State<ArtworkWidget> {
children: [
Image(
image: ScrollAwareImageProvider(
context: c,
context: _disposableContext,
imageProvider: ResizeImage.resizeIfNeeded(
null,
finalCache,
Expand Down

0 comments on commit 55cf7f7

Please sign in to comment.