Skip to content

Commit

Permalink
Playlist support. Play whole book instead of a chapter.
Browse files Browse the repository at this point in the history
README.md updated.
LICENSE added.
Bug fixes, code improvements and more.
  • Loading branch information
ShokhrukhbekYuldoshev committed Mar 23, 2024
1 parent 7ffbb7d commit bdc9a19
Show file tree
Hide file tree
Showing 22 changed files with 825 additions and 224 deletions.
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2024 Shokhrukhbek Yuldoshev

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
162 changes: 152 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,158 @@
# audiobooks
# 🎧📕 Audiobooks

A new Flutter project.
Listen to your favorite audiobooks for free! Immerse yourself in the world of audiobooks with our app, built on Clean Architecture principles. Enjoy a vast selection of audiobooks, all while benefiting from a scalable, maintainable, and future-proof app structure.

## Getting Started
NOTE: This app is still in development. iOS version may not work as expected.

This project is a starting point for a Flutter application.
## 📱 Platforms

A few resources to get you started if this is your first Flutter project:
- Android
- iOS

- [Lab: Write your first Flutter app](https://docs.flutter.dev/get-started/codelab)
- [Cookbook: Useful Flutter samples](https://docs.flutter.dev/cookbook)
## ✨ Features

For help getting started with Flutter development, view the
[online documentation](https://docs.flutter.dev/), which offers tutorials,
samples, guidance on mobile development, and a full API reference.
- [x] Audio playback online
- [x] Download audiobooks
- [x] Play downloaded audiobooks
- [x] Delete downloaded audiobooks
- [x] Background audio
- [x] Notification controls
- [x] Lock screen controls
- [x] Play, pause, skip, previous, seek, rewind
- [x] Shuffle and repeat
- [ ] Search for audiobooks
- [x] Playlists (whole book)
- [ ] Favorites
- [ ] Sleep timer
- [x] Settings
- [x] Themes (Dark, Light, System)

## 📸 Screenshots

<!-- Variables -->

[home-light]: screenshots/home-light.jpg 'Light theme'
[home-dark]: screenshots/home-dark.jpg 'Dark theme'
[audiobook-details]: screenshots/audiobook-details.jpg 'Audiobook details'
[audiobook-details-scroll]: screenshots/audiobook-details-scroll.jpg 'Audiobook details scroll'
[player]: screenshots/player.jpg 'Player'
[settings]: screenshots/settings.jpg 'Settings'

<!-- Table -->

| Light theme | Dark theme | Audiobook details |
| :-----------------------: | :---------------------: | --------------------------------------- |
| ![home-light][home-light] | ![home-dark][home-dark] | ![audiobook-details][audiobook-details] |

| Audiobook details scroll | Player | Settings |
| ----------------------------------------------------- | ----------------- | --------------------- |
| ![audiobook-details-scroll][audiobook-details-scroll] | ![player][player] | ![settings][settings] |

## 📚 Dependencies

| Name | Version | Description |
| ----------------------------------------------------------------------------- | ------------- | ----------------------------------------------------------------------------------------------------------------------------------------------- |
| [connectivity_plus](https://pub.dev/packages/connectivity_plus) | 6.0.1 | A Flutter plugin for discovering network connectivity configurations: Wi-Fi, mobile, etc. |
| [dio](https://pub.dev/packages/dio) | 5.4.1 | A powerful package for Dart, which supports Interceptors, Global configuration, FormData, Request Cancellation, File downloading, Timeout, etc. |
| [get_it](https://pub.dev/packages/get_it) | 7.6.7 | Simple service locator for Dart and Flutter projects and works with all kinds of objects: singletons, factories, lazy singletons, etc. |
| [bloc](https://pub.dev/packages/bloc) | 8.1.3 | A predictable state management library |
| [flutter_bloc](https://pub.dev/packages/flutter_bloc) | 8.1.4 | Flutter widgets that require a Bloc to function |
| [equatable](https://pub.dev/packages/equatable) | 2.0.5 | A Dart package that helps to simplify equality comparisons. |
| [dartz](https://pub.dev/packages/dartz) | 0.10.1 | A Dart functional programming library inspired by Haskell. |
| [flutter_widget_from_html](https://pub.dev/packages/flutter_widget_from_html) | 0.14.11 | A Flutter package to render widgets from HTML strings. |
| [cached_network_image](https://pub.dev/packages/cached_network_image) | 3.3.1 | A Flutter library to show images from the internet and keep them in the cache directory. |
| [xml](https://pub.dev/packages/xml) | 6.5.0 | A Dart XML parser and serializer. |
| [url_launcher](https://pub.dev/packages/url_launcher) | 6.2.5 | A Flutter plugin for launching URLs in mobile applications. |
| [shimmer](https://pub.dev/packages/shimmer) | 3.0.0 | A Flutter package that provides an easy way to add shimmer effect to your Flutter app. |
| [just_audio](https://pub.dev/packages/just_audio) | 0.9.36 | A Flutter plugin for playing audio. |
| [just_audio_background](https://pub.dev/packages/just_audio_background) | 0.0.1-beta.11 | A Flutter plugin for playing audio in the background. |
| [path](https://pub.dev/packages/path) | 1.9.0 | A Dart package for manipulating file paths. |
| [path_provider](https://pub.dev/packages/path_provider) | 2.1.2 | A Flutter plugin for finding commonly used locations on the filesystem. |
| [flutter_downloader](https://pub.dev/packages/flutter_downloader) | 1.11.6 | A Flutter plugin for downloading files directly to the device's storage. |
| [sqflite](https://pub.dev/packages/sqflite) | 2.3.2 | A Flutter plugin for SQLite, a self-contained, high-reliability, embedded, SQL database engine. |
| [package_info_plus](https://pub.dev/packages/package_info_plus) | 4.2.0 | A Flutter plugin for querying information about the application package. |
| [permission_handler](https://pub.dev/packages/permission_handler) | 11.3.0 | A Flutter plugin for requesting and checking permissions. |
| [shared_preferences](https://pub.dev/packages/shared_preferences) | 2.2.2 | A Flutter plugin for reading and writing simple key-value pairs. |

## 📦 Installation

### Prerequisites

- Flutter
- Android Studio / Xcode

### Setup

1. Clone the repo

```sh
git clone
```

2. Install dependencies

```sh
dart pub get
```

3. Run the app

```sh
flutter run
```

## ❗ Permissions

### Android

```xml
<!-- url_launcher -->
<queries>
<intent>
<action android:name="android.intent.action.VIEW" />
<data android:scheme="https" />
</intent>
</queries>
<!-- Internet permission -->
<uses-permission android:name="android.permission.INTERNET" />
<!-- Android 13+ notification -->
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
<!-- Audio service -->
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
```

### iOS

```xml
<!-- url_launcher -->
<key>LSApplicationQueriesSchemes</key>
<array>
<string>https</string>
</array>
<key>UIBackgroundModes</key>
<array>
<string>audio</string>
</array>
```

## 🤝 Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

## 📝 License

Distributed under the MIT License. See [LICENSE](LICENSE) for more information.

## 📧 Contact

- [Email](mailto:shokhrukhbekdev@gmail.com)
- [GitHub](https://github.com/ShokhrukhbekYuldoshev)

## 🌟 Show your support

Give a ⭐️ if you like this project!
10 changes: 6 additions & 4 deletions lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
import 'package:audiobooks/src/core/themes/cubit/theme_cubit.dart';
import 'package:audiobooks/src/presentation/bloc/settings/settings_cubit.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_downloader/flutter_downloader.dart';
import 'package:permission_handler/permission_handler.dart';

import 'package:audiobooks/src/app.dart';
import 'package:audiobooks/src/core/di/service_locator.dart';
import 'package:audiobooks/src/core/themes/cubit/theme_cubit.dart';
import 'package:audiobooks/src/domain/repositories/just_audio_player.dart';
import 'package:audiobooks/src/presentation/bloc/home/home_bloc.dart';

// TODO: implement playlist (whole book) instead of single book chapter
import 'package:audiobooks/src/presentation/bloc/player/player_bloc.dart';
import 'package:audiobooks/src/presentation/bloc/settings/settings_cubit.dart';

Future<void> main() async {
// Ensure that the Flutter binding has been initialized
Expand Down Expand Up @@ -42,6 +41,9 @@ Future<void> main() async {
BlocProvider(
create: (context) => sl<HomeBloc>()..add(GetHomePageEvent()),
),
BlocProvider(
create: (context) => sl<PlayerBloc>(),
),
BlocProvider(
create: (context) => sl<ThemeCubit>(),
),
Expand Down
1 change: 1 addition & 0 deletions lib/src/app.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class MyApp extends StatelessWidget {
}

return MaterialApp(
debugShowCheckedModeBanner: false,
title: 'Audiobooks',
themeMode: themeMode,
theme: sl<AppTheme>().lightTheme,
Expand Down
7 changes: 7 additions & 0 deletions lib/src/core/di/service_locator.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'package:audiobooks/src/core/themes/cubit/theme_cubit.dart';
import 'package:audiobooks/src/presentation/bloc/player/player_bloc.dart';
import 'package:audiobooks/src/presentation/bloc/settings/settings_cubit.dart';
import 'package:connectivity_plus/connectivity_plus.dart';
import 'package:get_it/get_it.dart';
Expand Down Expand Up @@ -85,6 +86,12 @@ void init() {
getAuthorsUseCase: sl(),
),
);
sl.registerFactory(
() => PlayerBloc(
player: sl(),
),
);

// Cubit
sl.registerFactory(() => ThemeCubit());
sl.registerFactory(() => SettingsCubit());
Expand Down
9 changes: 0 additions & 9 deletions lib/src/core/helpers/helpers.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import 'dart:io';
import 'package:cached_network_image/cached_network_image.dart';
import 'package:flutter/material.dart';
import 'package:path_provider/path_provider.dart';

Expand All @@ -17,14 +16,6 @@ bool canLoadImage(String image) {
return true;
}

ImageProvider<Object> showImage(String imageUrl) {
if (canLoadImage(imageUrl)) {
return CachedNetworkImageProvider(imageUrl);
} else {
return const AssetImage('assets/images/cover.jpg') as ImageProvider;
}
}

void showSnackBar(BuildContext context, String message) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
Expand Down
33 changes: 18 additions & 15 deletions lib/src/core/helpers/play_audiobook.dart
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import 'package:audiobooks/src/core/network/network_info.dart';
import 'package:flutter/material.dart';
import 'package:path_provider/path_provider.dart';

import 'package:audiobooks/src/core/di/service_locator.dart';
import 'package:audiobooks/src/core/helpers/helpers.dart';
import 'package:audiobooks/src/core/network/network_info.dart';
import 'package:audiobooks/src/domain/entities/audiobook_entity.dart';
import 'package:audiobooks/src/domain/entities/rss_entity.dart';
import 'package:audiobooks/src/domain/repositories/just_audio_player.dart';
Expand All @@ -20,14 +19,27 @@ Future<void> playAudiobook(
);
}

String url = item.enclosureUrl;
// Play the audiobook
final player = sl<JustAudioPlayer>();

List<RssItemEntity> playlist = List.generate(
audiobook.rssFeed!.channel.items.length,
(index) {
final item = audiobook.rssFeed!.channel.items[index];
return item;
},
);

if (playlist.isEmpty) {
return;
}

// if current item is downloaded
bool networkConnected = await sl<NetworkInfo>().isConnected;
bool fileExists = await isFileExists(item.enclosureUrl.split('/').last);

// Check if file exists
if (fileExists) {
final directory = await getExternalStorageDirectory();
url = '${directory!.path}/${item.enclosureUrl.split('/').last}';
}
// if network is not connected and file does not exist
else if (!networkConnected && context.mounted) {
Expand All @@ -37,14 +49,5 @@ Future<void> playAudiobook(
);
}

// Play the audiobook
final player = sl<JustAudioPlayer>();
await player.load(
url,
item.episode,
item.title,
audiobook.title,
audiobook.rssFeed!.channel.itunesImageHref,
);
await player.play();
await player.load(audiobook, playlist, item);
}
Loading

0 comments on commit bdc9a19

Please sign in to comment.