Skip to content

Commit

Permalink
Merge pull request #1364 from ardriveapp/PE-4582-audio-preview-in-app
Browse files Browse the repository at this point in the history
PE-4582: Audio Preview
  • Loading branch information
kunstmusik authored Sep 27, 2023
2 parents e0301fa + b0753ab commit bbee6c2
Show file tree
Hide file tree
Showing 14 changed files with 854 additions and 111 deletions.
3 changes: 2 additions & 1 deletion assets/config/dev.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
"allowedDataItemSizeForTurbo": 500000,
"enableQuickSyncAuthoring": true,
"enableMultipleFileDownload": true,
"enableVideoPreview": false,
"enableVideoPreview": true,
"enableAudioPreview": true,
"stripePublishableKey": "pk_test_51JUAtwC8apPOWkDLh2FPZkQkiKZEkTo6wqgLCtQoClL6S4l2jlbbc5MgOdwOUdU9Tn93NNvqAGbu115lkJChMikG00XUfTmo2z",
"enablePins": true
}
1 change: 1 addition & 0 deletions assets/config/prod.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"enableQuickSyncAuthoring": true,
"enableMultipleFileDownload": true,
"enableVideoPreview": false,
"enableAudioPreview": true,
"stripePublishableKey": "pk_live_51JUAtwC8apPOWkDLMQqNF9sPpfneNSPnwX8YZ8y1FNDl6v94hZIwzgFSYl27bWE4Oos8CLquunUswKrKcaDhDO6m002Yj9AeKj",
"enablePins": true
}
1 change: 1 addition & 0 deletions assets/config/staging.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"enableQuickSyncAuthoring": true,
"enableMultipleFileDownload": true,
"enableVideoPreview": false,
"enableAudioPreview": true,
"stripePublishableKey": "pk_live_51JUAtwC8apPOWkDLMQqNF9sPpfneNSPnwX8YZ8y1FNDl6v94hZIwzgFSYl27bWE4Oos8CLquunUswKrKcaDhDO6m002Yj9AeKj",
"enablePins": true
}
42 changes: 41 additions & 1 deletion lib/blocs/fs_entry_preview/fs_entry_preview_cubit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,15 @@ class FsEntryPreviewCubit extends Cubit<FsEntryPreviewState> {
}

break;

case 'audio':
_previewAudio(
fileKey != null,
selectedItem,
previewUrl,
);
break;

case 'video':
_previewVideo(
fileKey != null,
Expand Down Expand Up @@ -175,6 +184,16 @@ class FsEntryPreviewCubit extends Cubit<FsEntryPreviewState> {
case 'image':
emitImagePreview(file, previewUrl);
break;

case 'audio':
_previewAudio(
(selectedItem as FileDataTableItem).pinnedDataOwnerAddress ==
null &&
drive.isPrivate,
selectedItem,
previewUrl,
);
break;
case 'video':
_previewVideo(
drive.isPrivate,
Expand All @@ -193,6 +212,23 @@ class FsEntryPreviewCubit extends Cubit<FsEntryPreviewState> {
}
}

void _previewAudio(
bool isPrivate, FileDataTableItem selectedItem, previewUrl) {
if (_configService.config.enableAudioPreview) {
if (isPrivate) {
emit(FsEntryPreviewUnavailable());
return;
}

emit(FsEntryPreviewAudio(
filename: selectedItem.name, previewUrl: previewUrl));

return;
}

emit(FsEntryPreviewUnavailable());
}

void _previewVideo(
bool isPrivate, FileDataTableItem selectedItem, previewUrl) {
if (_configService.config.enableVideoPreview) {
Expand All @@ -201,7 +237,8 @@ class FsEntryPreviewCubit extends Cubit<FsEntryPreviewState> {
return;
}

emit(FsEntryPreviewVideo(previewUrl: previewUrl));
emit(FsEntryPreviewVideo(
filename: selectedItem.name, previewUrl: previewUrl));

return;
}
Expand Down Expand Up @@ -298,6 +335,9 @@ class FsEntryPreviewCubit extends Cubit<FsEntryPreviewState> {
case 'image':
return supportedImageTypesInFilePreview
.any((element) => element.contains(fileExtension));
case 'audio':
return audioContentTypes
.any((element) => element.contains(fileExtension));
case 'video':
return videoContentTypes
.any((element) => element.contains(fileExtension));
Expand Down
14 changes: 9 additions & 5 deletions lib/blocs/fs_entry_preview/fs_entry_preview_state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -37,21 +37,25 @@ class FsEntryPreviewImage extends FsEntryPreviewSuccess {
}

class FsEntryPreviewAudio extends FsEntryPreviewSuccess {
const FsEntryPreviewAudio({
required String previewUrl,
}) : super(previewUrl: previewUrl);
final String filename;
const FsEntryPreviewAudio(
{required String previewUrl, required this.filename})
: super(previewUrl: previewUrl);

@override
List<Object> get props => [previewUrl];
List<Object> get props => [previewUrl, filename];
}

class FsEntryPreviewVideo extends FsEntryPreviewSuccess {
final String filename;

const FsEntryPreviewVideo({
required String previewUrl,
required this.filename,
}) : super(previewUrl: previewUrl);

@override
List<Object> get props => [previewUrl];
List<Object> get props => [previewUrl, filename];
}

class FsEntryPreviewMemory extends FsEntryPreviewSuccess {
Expand Down
14 changes: 14 additions & 0 deletions lib/dev_tools/app_dev_tools.dart
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,19 @@ class AppConfigWindowManagerState extends State<AppConfigWindowManager> {
type: ArDriveDevToolOptionType.bool,
);

ArDriveDevToolOption enableAudioPreviewOption = ArDriveDevToolOption(
name: 'enableAudioPreview',
value: settings.enableAudioPreview,
onChange: (value) {
setState(() {
configService.updateAppConfig(
settings.copyWith(enableAudioPreview: value),
);
});
},
type: ArDriveDevToolOptionType.bool,
);

ArDriveDevToolOption autoSyncIntervalInSecondsOption = ArDriveDevToolOption(
name: 'autoSyncIntervalInSeconds',
value: settings.autoSyncIntervalInSeconds,
Expand Down Expand Up @@ -323,6 +336,7 @@ class AppConfigWindowManagerState extends State<AppConfigWindowManager> {
enableQuickSyncAuthoringOption,
enableMultipleFileDownloadOption,
enableVideoPreviewOption,
enableAudioPreviewOption,
enableSeedPhreaseLogin,
allowedDataItemSizeForTurboOption,
defaultArweaveGatewayUrlOption,
Expand Down
4 changes: 4 additions & 0 deletions lib/l10n/app_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -1302,6 +1302,10 @@
"@noOneWillSee": {
"description": "Indicates that private content won't reach to the wrong hands"
},
"normal": "Normal",
"@normal": {
"description": "Menu entry for \"Normal\" speed playback on Audio and Video previews."
},
"noSubscriptions": "No subscriptions are needed!",
"@noSubscriptions": {
"description": "Payment philosophy"
Expand Down
Loading

0 comments on commit bbee6c2

Please sign in to comment.