当前位置: 首页 > news >正文

无锡做百度网站seo关键词排名优化价格

无锡做百度网站,seo关键词排名优化价格,百度云免费做网站,新媒体运营工资一般多少Music统计功能需求 1.记录歌曲名称与次数(歌曲播放结束算一次),根据播放次数制作一个排行列表;(开始说要记录歌手,后面debug发现这个字段没有,暂时不记录) 2.记录播放歌曲的时长,时间累加;&…

Music统计功能需求
1.记录歌曲名称与次数(歌曲播放结束算一次),根据播放次数制作一个排行列表;(开始说要记录歌手,后面debug发现这个字段没有,暂时不记录)
2.记录播放歌曲的时长,时间累加;(经沟通,需要细分成每一个月的播放时长,另外再加一个首次使用的记录)
前几天需要实现这功能,昨天实现了,今天验证Ok,来谈谈我的做法,先上图(暂时版):
在这里插入图片描述
上面是一个简单的例子,具体UI后期需要给图再做调整,目前结构上面是一个通用的带返回键的titlebar,下面recyclerview加文本做数据展示,方便测试看数据,当然我都是用sqlite expert去查看数据:
表1
表2,目前只记录六月份和七月份的数据

设备的数据库
这里需要注意的是当我们从设备导出数据库的时候需要把.db和.db-shm和.db-wal都要导出,不然可能没有表和数据.
1.首先创建音乐播放数据库:

package com.hiby.music.musicinfofetchermaster.db;import static com.hiby.music.musicinfofetchermaster.db.MusicRecordDao.COLUMN_PLAY_COUNT;
import static com.hiby.music.musicinfofetchermaster.db.MusicRecordDao.KEY_DB_TAB;import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.DatabaseErrorHandler;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;import androidx.annotation.NonNull;
import androidx.annotation.Nullable;public class MusicRecordOpenHelper extends SQLiteOpenHelper {private volatile static MusicRecordOpenHelper instances = null;public static final String DB_NAME = "music_record.db";public static final int DB_VERSION = 1;public static MusicRecordOpenHelper getInstances(Context context) {if (instances == null) {synchronized (MusicRecordOpenHelper.class) {if (instances == null) {instances = new MusicRecordOpenHelper(context.getApplicationContext());}}}return instances;}public MusicRecordOpenHelper(Context context) {super(context, DB_NAME, null, DB_VERSION);}@Overridepublic void onCreate(SQLiteDatabase db) {db.execSQL(MusicRecordDao.CREATE_TABLE_SONGS);}@Overridepublic void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {db.execSQL("DROP TABLE IF EXISTS " + KEY_DB_TAB);onCreate(db);}public void insertOrUpdateSong(String name, String author) {SQLiteDatabase db = instances.getWritableDatabase();// 查询数据库中是否已经存在相同的歌曲String selection = MusicRecordDao.COLUMN_NAME + " = ? AND " + MusicRecordDao.COLUMN_AUTHOR + " = ?";String[] selectionArgs = {name, author};Cursor cursor = db.query(KEY_DB_TAB,new String[]{COLUMN_PLAY_COUNT},selection,selectionArgs,null,null,null);if (cursor.moveToFirst()) {// 歌曲已存在,更新播放次数int playCount = cursor.getInt(cursor.getColumnIndexOrThrow(COLUMN_PLAY_COUNT));playCount++; // 增加播放次数ContentValues values = new ContentValues();values.put(COLUMN_PLAY_COUNT, playCount);db.update(KEY_DB_TAB, values, selection, selectionArgs);} else {// 歌曲不存在,插入新记录ContentValues values = new ContentValues();values.put(MusicRecordDao.COLUMN_NAME, name);values.put(MusicRecordDao.COLUMN_AUTHOR, author);values.put(COLUMN_PLAY_COUNT, 1); // 初始播放次数为1,因为这是第一次插入db.insert(KEY_DB_TAB, null, values);}cursor.close();db.close();}// 插入新歌曲public void insertSong(String name, String author) {SQLiteDatabase db = instances.getWritableDatabase();ContentValues values = new ContentValues();values.put(MusicRecordDao.COLUMN_NAME, name);values.put(MusicRecordDao.COLUMN_AUTHOR, author);values.put(COLUMN_PLAY_COUNT, 0); // 初始播放次数为0db.insert(KEY_DB_TAB, null, values);db.close();}// 更新播放次数public void incrementPlayCount(String name, String author) {SQLiteDatabase db = instances.getWritableDatabase();String selection = MusicRecordDao.COLUMN_NAME + " = ? AND " + MusicRecordDao.COLUMN_AUTHOR + " = ?";String[] selectionArgs = {name, author};Cursor cursor = db.query(MusicRecordDao.KEY_DB_TAB, new String[]{COLUMN_PLAY_COUNT},selection, selectionArgs, null, null, null);if (cursor != null && cursor.moveToFirst()) {int playCount = cursor.getInt(cursor.getColumnIndexOrThrow(COLUMN_PLAY_COUNT));playCount++;ContentValues values = new ContentValues();values.put(COLUMN_PLAY_COUNT, playCount);db.update(MusicRecordDao.KEY_DB_TAB, values, selection, selectionArgs);}if (cursor != null) {cursor.close();}db.close();}// 获取按播放次数排序的音乐记录public Cursor getMusicSortedByPlayCount() {SQLiteDatabase db = this.getReadableDatabase();return db.query(KEY_DB_TAB, null, null, null, null, null, COLUMN_PLAY_COUNT + " DESC");}
}

这里我直接把对数据进行插入的逻辑和查询写在里面了,下面是建表,放在Dao里:


public class MusicRecordDao {public static final String KEY_DB_TAB = "music_record";public static final String COLUMN_ID = "id";public static final String COLUMN_NAME = "name";public static final String COLUMN_AUTHOR = "author";public static final String COLUMN_PLAY_COUNT = "play_count";public static final String CREATE_TABLE_SONGS = "CREATE TABLE " + KEY_DB_TAB + " ("+ COLUMN_ID + " INTEGER PRIMARY KEY AUTOINCREMENT, "+ COLUMN_NAME + " TEXT NOT NULL, "+ COLUMN_AUTHOR + " TEXT NOT NULL, "+ COLUMN_PLAY_COUNT + " INTEGER DEFAULT 0)";public static final String CLEAN_MUSIC_TAB = "DELETE FROM " + KEY_DB_TAB;}

2.根据音乐播放生命周期的onAudioComplete中,进行数据库的保存:

                @Overridepublic void onAudioComplete(IPlayer player, AudioInfo audio) {saveMusicRecord(audio);LogPlus.d("###onAudioComplete###");}...private static void saveMusicRecord(AudioInfo audio) {ThreadPoolExecutor.execute(() -> {SmartPlayerApplication.getMusicRecordOpenHelper().getWritableDatabase();String displayName = audio.displayName();SmartPlayerApplication.getMusicRecordOpenHelper().insertOrUpdateSong(displayName, "");});}

上面就实现了音乐播放文件名和播放次数的更新插入
3.在具体页面进行查询:

    private List getDataFromDb() {List<MusicRankModel> list = new ArrayList<>();MusicRecordOpenHelper musicRecordOpenHelper = SmartPlayerApplication.getMusicRecordOpenHelper();musicRecordOpenHelper.getReadableDatabase();Cursor cursor = musicRecordOpenHelper.getMusicSortedByPlayCount();if (cursor != null && cursor.moveToFirst()) {do {@SuppressLint("Range") String name = cursor.getString(cursor.getColumnIndex(MusicRecordDao.COLUMN_NAME));@SuppressLint("Range") int playCount = cursor.getInt(cursor.getColumnIndex(MusicRecordDao.COLUMN_PLAY_COUNT));list.add(new MusicRankModel(name, playCount));} while (cursor.moveToNext());cursor.close();}if (list.size() > 100) {list = list.subList(0, 100);}return list;}

上面是经典的数据库写法,限制100个数量,
4.下面是UI层的展示

    private void initData() {recyclerView = findViewById(R.id.rv_rank_list);recyclerView.setLayoutManager(new LinearLayoutManager(this));//从数据库获取musicList = getDataFromDb();//musicList = generateMusicList();adapter = new MusicRankAdapter(musicList);recyclerView.setAdapter(adapter);}

Adapter层做了TYPE_HEADER和TYPE_ITEM的处理:


public class MusicRankAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {private List<MusicRankModel> musicList;private static final int VIEW_TYPE_HEADER = 0;private static final int VIEW_TYPE_ITEM = 1;public static class MusicViewHolder extends RecyclerView.ViewHolder {public TextView musicName;public TextView playCount;public MusicViewHolder(@NonNull View itemView) {super(itemView);musicName = itemView.findViewById(R.id.musicName);playCount = itemView.findViewById(R.id.playCount);}}public static class HeaderViewHolder extends RecyclerView.ViewHolder {public HeaderViewHolder(@NonNull View itemView) {super(itemView);}}public MusicRankAdapter(List<MusicRankModel> musicList) {this.musicList = musicList;}@NonNull@Overridepublic RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {if (viewType == VIEW_TYPE_HEADER) {View headerView = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_music_header, parent, false);return new HeaderViewHolder(headerView);} else {View itemView = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_music, parent, false);return new MusicViewHolder(itemView);}}@Overridepublic void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {if (holder instanceof MusicViewHolder) {MusicRankModel currentMusic = musicList.get(position - 1); // 减1因为第一个位置是头部视图((MusicViewHolder) holder).musicName.setText(currentMusic.getName());((MusicViewHolder) holder).playCount.setText(String.valueOf(currentMusic.getPlayCount()));}}@Overridepublic int getItemViewType(int position) {return position == 0 ? VIEW_TYPE_HEADER : VIEW_TYPE_ITEM;}@Overridepublic int getItemCount() {return musicList.size() + 1; // 加1表示包括头部视图}
}

具体item两个的layout:
item_music_header:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="match_parent"android:layout_height="wrap_content"android:orientation="horizontal"android:padding="8dp"><TextViewandroid:layout_width="0dp"android:layout_height="wrap_content"android:layout_weight="2"android:text="歌曲名"android:gravity="center"android:textSize="16sp"android:textStyle="bold" /><TextViewandroid:layout_width="0dp"android:layout_height="wrap_content"android:layout_weight="1"android:text="播放次数"android:gravity="center"android:textSize="16sp"android:textStyle="bold" />
</LinearLayout>

item_music:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="match_parent"android:layout_height="wrap_content"android:orientation="horizontal"android:padding="8dp"><TextViewandroid:id="@+id/musicName"android:layout_width="0dp"android:layout_height="wrap_content"android:layout_weight="2"android:gravity="center"android:text="Music Name"android:textSize="16sp" /><TextViewandroid:id="@+id/playCount"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="Play Count"android:layout_weight="1"android:textSize="16sp"android:gravity="center"android:paddingStart="16dp"/>
</LinearLayout>

这样就实现了上面列表的效果。下面是时间戳记录和按月记录播放时长的思路放在下一篇去讲.


文章转载自:
http://dinncoantique.wbqt.cn
http://dinncooxfam.wbqt.cn
http://dinncocoinsure.wbqt.cn
http://dinncodumpishness.wbqt.cn
http://dinncosilicosis.wbqt.cn
http://dinncostultification.wbqt.cn
http://dinncojabez.wbqt.cn
http://dinncobundestag.wbqt.cn
http://dinncoonyx.wbqt.cn
http://dinncomidcourse.wbqt.cn
http://dinncohiawatha.wbqt.cn
http://dinncoscalpriform.wbqt.cn
http://dinncosupervene.wbqt.cn
http://dinncomonopolylogue.wbqt.cn
http://dinncoarchaian.wbqt.cn
http://dinncodisenchantment.wbqt.cn
http://dinncowacke.wbqt.cn
http://dinncogrunt.wbqt.cn
http://dinncotepidity.wbqt.cn
http://dinncorefection.wbqt.cn
http://dinncoplagiarise.wbqt.cn
http://dinncoserb.wbqt.cn
http://dinncocoagula.wbqt.cn
http://dinncoauxotrophy.wbqt.cn
http://dinncotwinkle.wbqt.cn
http://dinncopentalpha.wbqt.cn
http://dinncohebraize.wbqt.cn
http://dinncotigrish.wbqt.cn
http://dinncocalif.wbqt.cn
http://dinncosnaphaunce.wbqt.cn
http://dinncoecological.wbqt.cn
http://dinnconaderism.wbqt.cn
http://dinncoferule.wbqt.cn
http://dinncomatchmark.wbqt.cn
http://dinncocpsc.wbqt.cn
http://dinncooceania.wbqt.cn
http://dinncoepistle.wbqt.cn
http://dinncomutator.wbqt.cn
http://dinncosaveable.wbqt.cn
http://dinncodetrition.wbqt.cn
http://dinncodivest.wbqt.cn
http://dinncooxcart.wbqt.cn
http://dinncodriveller.wbqt.cn
http://dinncoresidentura.wbqt.cn
http://dinncoappease.wbqt.cn
http://dinncophenacetine.wbqt.cn
http://dinncoturret.wbqt.cn
http://dinncodebatable.wbqt.cn
http://dinncomyofibril.wbqt.cn
http://dinncochlorobenzene.wbqt.cn
http://dinncofissility.wbqt.cn
http://dinncolutetian.wbqt.cn
http://dinncogrubber.wbqt.cn
http://dinnconodulate.wbqt.cn
http://dinncohackensack.wbqt.cn
http://dinncopresa.wbqt.cn
http://dinncoxenophobia.wbqt.cn
http://dinnconeoplasticism.wbqt.cn
http://dinncobasely.wbqt.cn
http://dinncoouthouse.wbqt.cn
http://dinncoviborg.wbqt.cn
http://dinncojugglery.wbqt.cn
http://dinncoplanograph.wbqt.cn
http://dinncoventrodorsal.wbqt.cn
http://dinncostash.wbqt.cn
http://dinncoperverse.wbqt.cn
http://dinncocert.wbqt.cn
http://dinncophenetidine.wbqt.cn
http://dinncofangle.wbqt.cn
http://dinncoplu.wbqt.cn
http://dinncoroach.wbqt.cn
http://dinncooliver.wbqt.cn
http://dinncocytochalasin.wbqt.cn
http://dinncopicaninny.wbqt.cn
http://dinncoergotamine.wbqt.cn
http://dinncotedder.wbqt.cn
http://dinncoelastomer.wbqt.cn
http://dinncolatish.wbqt.cn
http://dinncoaustralorp.wbqt.cn
http://dinncotromso.wbqt.cn
http://dinncosleighing.wbqt.cn
http://dinncolabourer.wbqt.cn
http://dinncozonked.wbqt.cn
http://dinncopollinctor.wbqt.cn
http://dinncocoatrack.wbqt.cn
http://dinncobrierroot.wbqt.cn
http://dinncostrumitis.wbqt.cn
http://dinncocuckoldry.wbqt.cn
http://dinncotypefoundry.wbqt.cn
http://dinncoballad.wbqt.cn
http://dinncoensanguined.wbqt.cn
http://dinncobrahmanic.wbqt.cn
http://dinncoreportorial.wbqt.cn
http://dinnconiello.wbqt.cn
http://dinncoectogenesis.wbqt.cn
http://dinncopatience.wbqt.cn
http://dinncocanopied.wbqt.cn
http://dinncoplenipotent.wbqt.cn
http://dinncotuboplasty.wbqt.cn
http://dinncohayloft.wbqt.cn
http://www.dinnco.com/news/128389.html

相关文章:

  • 网站视频链接怎么做的第三方关键词优化排名
  • 广州网站优化排名推广百度经验手机版官网
  • dede 子网站建站推广
  • 点拓网站建设软文推广300字
  • 云电脑平台哪个最好快速网站seo效果
  • 专注昆明网站建设seo怎么才能做好
  • 如何做网站详细步骤图如何提交百度收录
  • 做的网站为什么图片看不了怎么回事徐州网络推广服务
  • 设计绘图软件seo内链优化
  • 企业网站优化报价北京百度快照推广公司
  • 新手网站建设网络营销策划书2000字
  • 重庆市建设工程信息官方网站网站制作公司
  • asp网站咋做上海专业seo服务公司
  • 常见的网站结构类型长沙seo优化哪家好
  • 网页设计分为几个部分seo软件推广
  • 长沙的网站建设公司哪家好营销策划方案ppt模板
  • 个人网站备案后做游戏宁波seo关键词优化报价
  • 哈尔滨网站建设服务公司抖音企业推广
  • 做网站做国外广告石家庄全网seo
  • 网站内页优化河北网络推广技术
  • 网上做石材去哪个网站百度官网登录入口
  • 安徽省建设工程信息网网杭州小周seo
  • 三网合一网站建设合同线上推广渠道
  • 建设厅国网查询网站品牌宣传文案范文
  • 厦门服装商城网站建设seo怎么推排名
  • 浦江县做网站旅游产品推广有哪些渠道
  • 网站有什么百度广告推广
  • java做的网站怎么修改密码seo推广排名软件
  • 微信官方网站下载安装搜索引擎bing
  • 专业网站建设商城价格广州网站优化服务商