[英]Dynamic Playlists for MP3 files Android
I am quite new to android development, and i'm currently attempting to make a media player. 我对android开发非常陌生,目前正在尝试制作媒体播放器。 My next goal on it is to implement a playlist system that items can be added to, as well as removed, and can be auto removed when onCompleteListener() is triggered. 我的下一个目标是实现一个播放列表系统,可以在其中添加和删除项目,并且可以在触发onCompleteListener()时将其自动删除。 I am currently pulling songs from the SD card using contentResolver 我目前正在使用contentResolver从SD卡中提取歌曲
public void getSongList(){
ContentResolver musicResolver=getContentResolver();
Uri musicUri= MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;
Cursor musicCursor=musicResolver.query(musicUri,null,null,null,null);
if(musicCursor!=null && musicCursor.moveToFirst()){
//get columns
int titleColumn = musicCursor.getColumnIndex
(android.provider.MediaStore.Audio.Media.TITLE);
int idColumn = musicCursor.getColumnIndex
(android.provider.MediaStore.Audio.Media._ID);
int artistColumn = musicCursor.getColumnIndex
(android.provider.MediaStore.Audio.Media.ARTIST);
//add songs to list
do {
long thisId = musicCursor.getLong(idColumn);
String thisTitle = musicCursor.getString(titleColumn);
String thisArtist = musicCursor.getString(artistColumn);
songList.add(new Song(thisId, thisTitle, thisArtist));
}
while (musicCursor.moveToNext());
}
}
At this point I have it set up thus that I can click on the item in a listView and it can start playing the song through a service. 至此,我已经进行了设置,因此可以单击listView中的项目,它可以通过服务开始播放歌曲。 My question is what is the best way to store the data of the song URI and position. 我的问题是,存储歌曲URI和位置数据的最佳方法是什么。 I would also like for the application to be able to store the playlists last position when the app restarts, even after an onDestroy(). 我还希望该应用程序能够在应用程序重新启动时存储播放列表的最后位置,即使在onDestroy()之后也是如此。 I'm not sure what kind of data sets would be best used to store that data, and how to retrieve it. 我不确定哪种数据集最适合用于存储该数据以及如何检索它。 Any help would be much appreciated! 任何帮助将非常感激!
You need to persisting the song data to the device . 您需要将歌曲数据保存到设备中 。
The Android framework offers several options and strategies for persistence: Android框架提供了多种持久性选项和策略:
Use Cases 用例
Each storage option has typically associated use cases as follows: 每个存储选项通常具有以下相关的用例:
Read more: Persisting Data To Device . 阅读更多:将数据持久存储到设备 。
You can use one of the options, but for your purpose, SQLite Database or ORM is the better options. 您可以使用其中一个选项,但是出于您的目的, SQLite Database或ORM是更好的选择。
You can visit Local Databases with SQLiteOpenHelper for SQLite Database. 您可以使用SQLiteOpenHelper访问SQLite数据库的本地数据库。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.