Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issues with PlaylistEntity #6

Closed
ghost opened this issue Sep 15, 2021 · 10 comments
Closed

Issues with PlaylistEntity #6

ghost opened this issue Sep 15, 2021 · 10 comments
Labels
PRI: High S: Fixed T: Bug Something isn't working

Comments

@ghost
Copy link

ghost commented Sep 15, 2021

I am facing these issues:

  1. playlistDateAdded is not being set when createPlaylist is called
  2. playlistSongs is not being persisted, it's empty list after app restart (?!)
@LucJosin LucJosin added PRI: High S: To-Do Feature or request that still need doing T: Bug Something isn't working labels Sep 16, 2021
@LucJosin
Copy link
Owner

LucJosin commented Sep 16, 2021

Oh, ok. The first issue is caused because i deprecated "playlistDataAdded" and didn't update the rest of the package.

But, the second one i couldn't reproduce. Can you give more details? Steps to Reproduce.

@LucJosin LucJosin added S: More info Further information is requested and removed S: To-Do Feature or request that still need doing labels Sep 16, 2021
@ghost
Copy link
Author

ghost commented Sep 16, 2021

Will provide more details about the second one, as soon as I create minimal reproducible code sample...

@ghost
Copy link
Author

ghost commented Sep 17, 2021

Due to the lack of time right now, I can't reproduce the exact issue I have, but I managed to reproduce something similar.

I have issue that after app restart, all songs inside all playlists are lost. I add them with addAllTo method.

Code below reproduce something similar - removed songs from playlist don't persist. Method - deleteFrom.

Run the main.dart file below:

import 'package:flutter/material.dart';
import 'package:on_audio_query/on_audio_query.dart';
import 'package:on_audio_room/on_audio_room.dart';

void main() async {
  await OnAudioRoom().initRoom(RoomType.PLAYLIST);
  runApp(
    MaterialApp(
      home: MyApp(),
    ),
  );
}

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  final OnAudioRoom _audioRoom = OnAudioRoom();
  final OnAudioQuery _audioQuery = OnAudioQuery();

  @override
  void initState() {
    super.initState();
    _requestPermission();
  }

  void _requestPermission() async {
    bool permissionStatus = await _audioQuery.permissionsStatus();
    if (!permissionStatus) {
      await _audioQuery.permissionsRequest();
    }
    setState(() {});
  }

  @override
  void dispose() {
    _audioRoom.closeRoom();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text("OnAudioRoom"),
        actions: [
          IconButton(
            onPressed: () async {
              await _audioRoom.createPlaylist("My Playlist");
            },
            icon: const Icon(Icons.add),
          ),
          IconButton(
            onPressed: () {
              Navigator.of(context).push(
                MaterialPageRoute(builder: (_) => Information()),
              );
            },
            icon: const Icon(Icons.queue_music_rounded),
          )
        ],
      ),
      body: FutureBuilder<List<SongModel>>(
        future: OnAudioQuery().querySongs(),
        builder: (_, item) {
          if (item.data != null) {
            List<SongModel> songs = item.data!;
            return ListView.builder(
              itemCount: songs.length,
              itemBuilder: (_, index) {
                return ListTile(
                  title: Text(songs[index].title),
                  subtitle: Text(songs[index].artist ?? "No artist"),
                  onTap: () async {
                    var _playlists = await _audioRoom.queryPlaylists();
                    await _audioRoom.addTo(
                      RoomType.PLAYLIST,
                      songs[index].getMap.toSongEntity(),
                      playlistKey: _playlists[0].key,
                    );
                  },
                );
              },
            );
          }
          return const Center(
            child: CircularProgressIndicator(),
          );
        },
      ),
    );
  }
}

class Information extends StatefulWidget {
  @override
  _InformationState createState() => _InformationState();
}

class _InformationState extends State<Information> {
  OnAudioRoom audioRoom = OnAudioRoom();

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text("My Playlist"),
      ),
      body: Center(
        child: FutureBuilder<List<PlaylistEntity?>>(
          future: OnAudioRoom().queryPlaylists(),
          builder: (context, item) {
            if (item.data == null) return const CircularProgressIndicator();

            if (item.data![0]!.playlistSongs.isEmpty)
              return const Text("No data found");

            List<SongEntity> songs = item.data![0]!.playlistSongs;
            return ListView.builder(
              itemCount: songs.length,
              itemBuilder: (context, index) {
                return ListTile(
                  title: Text(songs[index].title),
                  subtitle: Text(songs[index].dateAdded.toString()),
                  onTap: () async {
                    await audioRoom.deleteFrom(
                        RoomType.PLAYLIST, songs[index].id,
                        playlistKey: item.data![0]!.key);
                    setState(() {});
                  },
                );
              },
            );
          },
        ),
      ),
    );
  }
}

Steps to reproduce:

  1. click on "add" icon
  2. click on few songs to add them to playlist
  3. click on "playlist" icon to navigate to playlist page
  4. click on all added songs to remove them from playlist
  5. click on "back" button to navigate to home screen
  6. click to "playlist" icon to open playlists page again (see that playlist is empty)
  7. close the app from multitasking
  8. open the app again
  9. click "playlist" button to navigate to playlists page (see that playlist is NOT empty)

This seems to be a tricky issue. I will investigate it further when I have more time. Will try to reproduce issue I see in my own app.

Code run on real device, android 11.

@LucJosin
Copy link
Owner

After review the playlist methods, i noticed something. Calling any playlist method will work until app restart because i forgot to call updatePlaylist.

playlistSongs is not being persisted, it's empty list after app restart (?!)

But still can't reproduce this issue.

@ghost
Copy link
Author

ghost commented Sep 17, 2021

I don't know, but something is not right here. Will investigate it further once I have more time.

You cannot even reproduce the issue from code sample above?

@LucJosin
Copy link
Owner

I have issue that after app restart, all songs inside all playlists are lost. I add them with addAllTo method.

Have you tried using addTo method? This is the only method that actually save the songs.

You cannot even reproduce the issue from code sample above?

Yes i can, I'll do more tests and launch a fix to this issue.

@ghost
Copy link
Author

ghost commented Sep 17, 2021

Have you tried using addTo method? This is the only method that actually save the songs.

I didn't try. I am not close to laptop now, so can't try it atm. Hm, but why is there a difference between "addTo" and "addAllTo" method?

@LucJosin
Copy link
Owner

This update should fix this issue. If not, you can tell me.

@LucJosin LucJosin added S: Fixed and removed S: More info Further information is requested labels Sep 17, 2021
@ghost
Copy link
Author

ghost commented Sep 17, 2021

@LucasPJS Great! Will test it on Sunday, and report back to you.

@ghost
Copy link
Author

ghost commented Sep 19, 2021

@LucasPJS It has been fixed! Version 2.1.1 works great. Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
PRI: High S: Fixed T: Bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant