Skip to content

Commit

Permalink
shifted to lowQUrl for yt cause of highbandwidth problem
Browse files Browse the repository at this point in the history
  • Loading branch information
HemantKArya committed Mar 31, 2024
1 parent 2788817 commit 6313d58
Show file tree
Hide file tree
Showing 6 changed files with 90 additions and 69 deletions.
36 changes: 24 additions & 12 deletions android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,15 +1,26 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.WAKE_LOCK"/>
<uses-permission android:name="android.permission.FOREGROUND_SERVICE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.USE_FULL_SCREEN_INTENT"/>
<uses-permission android:name="android.permission.ACCESS_NOTIFICATION_POLICY" />
<application android:label="Bloomee" android:name="${applicationName}" android:hardwareAccelerated="true" android:icon="@mipmap/launcher_icon">
<activity android:name="com.ryanheise.audioservice.AudioServiceActivity" android:exported="true" android:launchMode="singleTop" android:theme="@style/LaunchTheme" android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode" android:hardwareAccelerated="true" android:windowSoftInputMode="adjustResize">
<application android:label="Bloomee"
android:name="${applicationName}"
android:hardwareAccelerated="true"
android:icon="@mipmap/launcher_icon">

<activity
android:name="com.ryanheise.audioservice.AudioServiceActivity"
android:exported="true"
android:launchMode="singleTask"
android:theme="@style/LaunchTheme"
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
android:hardwareAccelerated="true"
android:windowSoftInputMode="adjustResize">
<!-- Specifies an Android theme to apply to this Activity as soon as
the Android process has started. This theme is visible to the user
while the Flutter UI initializes. After that, this theme continues
Expand All @@ -27,13 +38,14 @@
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="text/plain" />
</intent-filter>
<intent-filter android:label="bloome">
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />

<data android:pathPattern=".*\\.blm" />
<data android:mimeType="*/*" /> </intent-filter>
<intent-filter android:label="Import Playlist">
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:pathPattern=".*\\.blm" />
<data android:mimeType="*/*" />

</intent-filter>
</activity>


Expand Down
5 changes: 1 addition & 4 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,7 @@ void processIncomingIntent(List<SharedMediaFile> _sharedFiles) {
}
});
}
} else if (Uri.parse(_sharedFiles[0].path)
.toFilePath()
.toString()
.contains(".blm")) {
} else if (_sharedFiles[0].mimeType == "application/octet-stream") {
BloomeeFileManager.importPlaylist(
Uri.parse(_sharedFiles[0].path).toFilePath().toString());
SnackbarService.showMessage("Playlist Imported");
Expand Down
6 changes: 3 additions & 3 deletions lib/repository/Youtube/youtube_api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,10 @@ class YouTubeServices {
String quality;
try {
quality = await BloomeeDBService.getSettingStr('quality',
defaultValue: 'High') ??
'High';
defaultValue: 'Low') ??
'Low';
} catch (e) {
quality = 'High';
quality = 'Low';
}
final Map? data = await formatVideo(video: res, quality: quality);
return data;
Expand Down
4 changes: 3 additions & 1 deletion lib/services/bloomeePlayer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ class BloomeeMusicPlayer extends BaseAudioHandler
return await refreshYtLink(id);
} else {
log("Link found in cache for vidId: $id", name: "bloomeePlayer");
return vidInfo.highQURL;
return vidInfo.lowQURL;
}
} else {
log("No cache found for vidId: $id", name: "bloomeePlayer");
Expand Down Expand Up @@ -158,6 +158,8 @@ class BloomeeMusicPlayer extends BaseAudioHandler

try {
getLinkOperation.then((tempStrmLink) async {
log("Got link: $tempStrmLink", name: "bloomeePlayer");
// AudioSource audioSource = AudioSource.uri(Uri.parse(tempStrmLink!));
await audioPlayer.setUrl(tempStrmLink!).then((value) {
isLinkProcessing.add(false);
if (super.mediaItem.value?.id == mediaItem.id && !isPaused) {
Expand Down
104 changes: 57 additions & 47 deletions lib/utils/file_manager.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'dart:convert';
import 'dart:developer';
import 'dart:io';
import 'package:Bloomee/screens/widgets/snackbar.dart';
import 'package:Bloomee/services/db/GlobalDB.dart';
import 'package:Bloomee/services/db/bloomee_db_service.dart';
import 'package:path_provider/path_provider.dart';
Expand Down Expand Up @@ -61,63 +62,72 @@ class BloomeeFileManager {

static Future<void> importPlaylist(String filePath) async {
//check if file is json or not
if (!filePath.endsWith('.blm')) {
log("Invalid file format", name: "FileManager");
return;
}
// if (!filePath.endsWith('.blm')) {
// log("Invalid file format", name: "FileManager");
// return;
// }
// import playlist from json file
await readFromJSON(filePath).then((playlistMap) async {
log("Playlist map: $playlistMap", name: "FileManager");
if (playlistMap != null && playlistMap.isNotEmpty) {
try {
bool playlistExists =
await isPlaylistExists(playlistMap['playlistName']);
int i = 1;
String playlistName = playlistMap['playlistName'];
while (playlistExists) {
playlistName = playlistMap['playlistName'] + "_$i";
playlistExists = await isPlaylistExists(playlistName);
i++;
}
log("Playlist name: $playlistName", name: "FileManager");
try {
await readFromJSON(filePath).then((playlistMap) async {
log("Playlist map: $playlistMap", name: "FileManager");
if (playlistMap != null && playlistMap.isNotEmpty) {
try {
bool playlistExists =
await isPlaylistExists(playlistMap['playlistName']);
int i = 1;
String playlistName = playlistMap['playlistName'];
while (playlistExists) {
playlistName = playlistMap['playlistName'] + "_$i";
playlistExists = await isPlaylistExists(playlistName);
i++;
}
log("Playlist name: $playlistName", name: "FileManager");

final mediaPlaylistDB = MediaPlaylistDB(
playlistName: playlistName,
);
final mediaPlaylistDB = MediaPlaylistDB(
playlistName: playlistName,
);

for (final mediaItemMap in playlistMap['mediaItems']) {
final mediaItemDB = MediaItemDB.fromMap(mediaItemMap);
await BloomeeDBService.addMediaItem(mediaItemDB, mediaPlaylistDB);
log("Media item imported successfully - ${mediaItemDB.title}",
name: "FileManager");
}
for (final mediaItemMap in playlistMap['mediaItems']) {
final mediaItemDB = MediaItemDB.fromMap(mediaItemMap);
await BloomeeDBService.addMediaItem(mediaItemDB, mediaPlaylistDB);
log("Media item imported successfully - ${mediaItemDB.title}",
name: "FileManager");
}

log("Playlist imported successfully");
} catch (e) {
log("Error importing playlist: $e");
log("Playlist imported successfully");
} catch (e) {
log("Error importing playlist: $e");
}
}
}
});
});
} catch (e) {
log("Invalid file format");
SnackbarService.showMessage("Invalid file format");
}
}

static void importMediaItem(String filePath) async {
if (!filePath.endsWith('.blm')) {
log("Invalid file format", name: "FileManager");
return;
}
// if (!filePath.endsWith('.blm')) {
// log("Invalid file format", name: "FileManager");
// return;
// }
// import media item from json file
await readFromJSON(filePath).then((mediaItemMap) {
if (mediaItemMap != null && mediaItemMap.isNotEmpty) {
try {
final mediaItemDB = MediaItemDB.fromMap(mediaItemMap);
BloomeeDBService.addMediaItem(
mediaItemDB, MediaPlaylistDB(playlistName: "Imported"));
log("Media item imported successfully");
} catch (e) {
log("Error importing media item: $e");
try {
await readFromJSON(filePath).then((mediaItemMap) {
if (mediaItemMap != null && mediaItemMap.isNotEmpty) {
try {
final mediaItemDB = MediaItemDB.fromMap(mediaItemMap);
BloomeeDBService.addMediaItem(
mediaItemDB, MediaPlaylistDB(playlistName: "Imported"));
log("Media item imported successfully");
} catch (e) {
log("Error importing media item: $e");
}
}
}
});
});
} catch (e) {
log("Invalid file format");
}
}

static Future<String?> writeToJSON(
Expand Down
4 changes: 2 additions & 2 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ dependencies:
carousel_slider: ^4.2.1
palette_generator: ^0.3.3+2
audio_video_progress_bar: ^1.0.1
just_audio: ^0.9.36
just_audio: ^0.9.37
just_audio_windows: ^0.2.0
audio_service: ^0.18.12
audio_service: ^0.18.13
audio_session: ^0.1.16
rxdart: ^0.27.7
go_router: ^10.1.0
Expand Down

0 comments on commit 6313d58

Please sign in to comment.