-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from lilmistake/lilmistake-dev [skip CI]
Big Changes + Refactoring
- Loading branch information
Showing
31 changed files
with
993 additions
and
129 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import 'package:flutter/material.dart'; | ||
|
||
extension WithGapY on List<Widget> { | ||
List<Widget> withGapY({double height = 15}) { | ||
List<Widget> children = toList(); | ||
List<Widget> result = []; | ||
for (var child in children) { | ||
result.add(child); | ||
result.add(SizedBox(height: height)); | ||
} | ||
return result; | ||
} | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
class Lyrics { | ||
final String lyrics; | ||
final String copyright; | ||
|
||
Lyrics({required this.copyright, required this.lyrics}); | ||
|
||
factory Lyrics.fromJson(Map<String, dynamic> json) { | ||
return Lyrics( | ||
copyright: json['data']['copyright'], lyrics: json['data']['lyrics']); | ||
} | ||
|
||
} |
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:just_audio/just_audio.dart'; | ||
import 'package:soundbox/core/models/lyrics_model.dart'; | ||
import 'package:soundbox/core/models/song_model.dart'; | ||
import 'package:soundbox/services/saavn_api_service.dart'; | ||
|
||
class SongProvider extends ChangeNotifier { | ||
final _queue = ConcatenatingAudioSource( | ||
useLazyPreparation: true, | ||
children: [], | ||
); | ||
final List<Song> _queueMeta = []; | ||
final AudioPlayer _player = AudioPlayer(); | ||
int _currentSongIndex = 0; | ||
bool _isPlaying = false; | ||
|
||
AudioPlayer get player => _player; | ||
bool get isPlaying => _isPlaying; | ||
Song? get currentSong => | ||
_queueMeta.isEmpty ? null : _queueMeta[_currentSongIndex]; | ||
List<Song>? get currentQueue => _queueMeta; | ||
ConcatenatingAudioSource get queue => _queue; | ||
int get currentSongIndex => _currentSongIndex; | ||
|
||
SongProvider() { | ||
_player.playingStream.listen((state) { | ||
_isPlaying = state; | ||
}); | ||
_player.currentIndexStream.listen((index) { | ||
if (index != null) { | ||
_currentSongIndex = index; | ||
notifyListeners(); | ||
} | ||
}); | ||
} | ||
|
||
Future<void> handlePausePlay() async { | ||
if (_player.playing) { | ||
await _player.pause(); | ||
} else { | ||
await _player.play(); | ||
} | ||
notifyListeners(); | ||
} | ||
|
||
Future<void> setAudioSource() async { | ||
await _player.setAudioSource(_queue, | ||
initialIndex: 0, initialPosition: Duration.zero); | ||
} | ||
|
||
Future<void> setCurrentSong(Song song) async { | ||
int c = _currentSongIndex; | ||
if (_queue.length == 0) c = -1; | ||
await _queue.insert( | ||
c + 1, AudioSource.uri(Uri.parse(song.downloadUrls.last.link))); | ||
|
||
if (_queueMeta.isEmpty) await setAudioSource(); | ||
_queueMeta.insert(c + 1, song); | ||
notifyListeners(); | ||
await Future.delayed(Durations.medium1); | ||
playNext(); | ||
} | ||
|
||
Future<void> addToQueue(Song song) async { | ||
await _queue.add(AudioSource.uri(Uri.parse(song.downloadUrls.last.link))); | ||
if (_queueMeta.isEmpty) await setAudioSource(); | ||
_queueMeta.add(song); | ||
notifyListeners(); | ||
} | ||
|
||
Future<void> seekToPoint(int seconds) async { | ||
Duration currentDuration = _player.position; | ||
await _player.seek(Duration(seconds: seconds + currentDuration.inSeconds)); | ||
notifyListeners(); | ||
} | ||
|
||
Future<void> playPrevious() async { | ||
Duration currentDuration = _player.position; | ||
if (currentDuration.inSeconds < 2) { | ||
await _player.seekToPrevious(); | ||
notifyListeners(); | ||
} else { | ||
seekToPoint(-currentDuration.inSeconds); | ||
} | ||
} | ||
|
||
Future<void> playNext() async { | ||
await _player.seekToNext(); | ||
if (!_player.playing) await _player.play(); | ||
notifyListeners(); | ||
} | ||
|
||
Stream<Duration> positionStream() { | ||
return _player.createPositionStream( | ||
maxPeriod: const Duration(milliseconds: 20), | ||
minPeriod: const Duration(milliseconds: 20), | ||
); | ||
} | ||
|
||
Future<void> getLyrics() async { | ||
Song song = _queueMeta[_currentSongIndex]; | ||
if (song.lyrics == null) { | ||
if (song.hasLyrics == false) { | ||
_queueMeta[_currentSongIndex].lyrics = 'No Lyrics Found'; | ||
} else { | ||
Lyrics? lyrics = await SaavnApiService().getLyrics(song.id); | ||
if (lyrics == null) { | ||
_queueMeta[_currentSongIndex].lyrics = 'No Lyrics Found'; | ||
} else { | ||
_queueMeta[_currentSongIndex].lyrics = lyrics.lyrics; | ||
} | ||
} | ||
notifyListeners(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
lib/home/widgets/home_app_bar.dart → lib/pages/home/home_app_bar.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:soundbox/core/extensions/with_gap_y.dart'; | ||
import 'package:soundbox/pages/home/home_app_bar.dart'; | ||
import 'package:soundbox/pages/home/home_queue_list.dart'; | ||
import 'package:soundbox/pages/search/search_bar.dart'; | ||
import 'package:soundbox/widgets/song_control_bar.dart'; | ||
|
||
class HomePage extends StatefulWidget { | ||
const HomePage({super.key}); | ||
|
||
@override | ||
State<HomePage> createState() => _HomePageState(); | ||
} | ||
|
||
class _HomePageState extends State<HomePage> { | ||
Widget drawer = const Drawer(); | ||
|
||
void setDrawer(Widget newDrawer) { | ||
setState(() { | ||
drawer = newDrawer; | ||
}); | ||
} | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return Scaffold( | ||
drawer: drawer, | ||
body: SafeArea( | ||
child: Padding( | ||
padding: const EdgeInsets.all(10), | ||
child: Stack( | ||
children: [ | ||
SingleChildScrollView( | ||
child: Column( | ||
crossAxisAlignment: CrossAxisAlignment.start, | ||
children: [ | ||
const HomeAppBar(), | ||
SongSearchBar(setDrawer: setDrawer), | ||
const HomeQueueList() | ||
].withGapY(height: 10), | ||
), | ||
), | ||
Align( | ||
alignment: Alignment.bottomCenter, | ||
child: SongControleBar(setDrawer: setDrawer)) | ||
], | ||
), | ||
), | ||
), | ||
); | ||
} | ||
} | ||
|
||
|
||
/* | ||
Self host the API | ||
Cache recently searched songs' results | ||
Create artist page - visible by clicking on their name under a song or maybe even by searching(?) | ||
Add functionality to add to favourites | ||
Add functionality to create playlist | ||
Add functionality to play the song | ||
Add functionality to show the lyrics | ||
Add functionality to generate playlists based on interest using ML | ||
*/ |
Oops, something went wrong.