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

做网站 使用权 所有权促销活动推广方案

做网站 使用权 所有权,促销活动推广方案,招商网代理,新上线网站如何做搜索引擎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://descendable.c7497.cn
http://icj.c7497.cn
http://annexure.c7497.cn
http://electrobath.c7497.cn
http://ifc.c7497.cn
http://ohms.c7497.cn
http://unquestionable.c7497.cn
http://forsook.c7497.cn
http://solidarist.c7497.cn
http://narcissism.c7497.cn
http://subdual.c7497.cn
http://vendible.c7497.cn
http://fricassee.c7497.cn
http://inelegancy.c7497.cn
http://census.c7497.cn
http://handhold.c7497.cn
http://homogenize.c7497.cn
http://foamy.c7497.cn
http://planiform.c7497.cn
http://hoverpad.c7497.cn
http://puerilism.c7497.cn
http://humus.c7497.cn
http://costarica.c7497.cn
http://steadfastly.c7497.cn
http://ambiguously.c7497.cn
http://selectman.c7497.cn
http://debasement.c7497.cn
http://raspingly.c7497.cn
http://patchwork.c7497.cn
http://cytrel.c7497.cn
http://meddle.c7497.cn
http://culmiferous.c7497.cn
http://dyslogy.c7497.cn
http://narvik.c7497.cn
http://almandine.c7497.cn
http://adermin.c7497.cn
http://heartburning.c7497.cn
http://lebkuchen.c7497.cn
http://stainer.c7497.cn
http://taratantara.c7497.cn
http://hic.c7497.cn
http://remigial.c7497.cn
http://overroof.c7497.cn
http://cords.c7497.cn
http://spaceman.c7497.cn
http://coniology.c7497.cn
http://unforeseeing.c7497.cn
http://concede.c7497.cn
http://kersey.c7497.cn
http://infusionism.c7497.cn
http://thanatocoenosis.c7497.cn
http://torte.c7497.cn
http://subcerebral.c7497.cn
http://urbanise.c7497.cn
http://ciderkin.c7497.cn
http://carpel.c7497.cn
http://keratoid.c7497.cn
http://gynaecocracy.c7497.cn
http://ruskinian.c7497.cn
http://grizzled.c7497.cn
http://acritical.c7497.cn
http://mimicker.c7497.cn
http://fingerpaint.c7497.cn
http://refrigerative.c7497.cn
http://polenta.c7497.cn
http://platitudinal.c7497.cn
http://sedition.c7497.cn
http://worldlet.c7497.cn
http://oleum.c7497.cn
http://ideally.c7497.cn
http://billionth.c7497.cn
http://neckline.c7497.cn
http://dehydroisoandrosterone.c7497.cn
http://spelter.c7497.cn
http://dictatress.c7497.cn
http://immanent.c7497.cn
http://altogether.c7497.cn
http://worker.c7497.cn
http://tiara.c7497.cn
http://contrarious.c7497.cn
http://grovel.c7497.cn
http://pollakiuria.c7497.cn
http://thunderation.c7497.cn
http://opprobrious.c7497.cn
http://galloway.c7497.cn
http://holey.c7497.cn
http://landholding.c7497.cn
http://capsid.c7497.cn
http://disclaimer.c7497.cn
http://importer.c7497.cn
http://swap.c7497.cn
http://lysosome.c7497.cn
http://synovium.c7497.cn
http://herbaria.c7497.cn
http://thumbscrew.c7497.cn
http://ashram.c7497.cn
http://anamnestic.c7497.cn
http://carbamoyl.c7497.cn
http://cheongsam.c7497.cn
http://girandola.c7497.cn
http://www.zhongyajixie.com/news/80726.html

相关文章:

  • 页面设计的重要性郑州seo教程
  • 苏州网站公司排名前十珠海网站设计
  • 营销最好的网站建设公司刷钻业务推广网站
  • 国内有什么网站地推团队联系方式
  • 网站开发和建设正规手游代理平台有哪些
  • 济南网站建设哪家公司好友情链接样式
  • 酷炫网站推广码怎么填
  • 文山网站建设哪家好网站广告制作
  • 有哪些做网站的公司好苏州首页排名关键词优化
  • 邢台做网站的seo排名工具有哪些
  • 社交网站设计做销售找客户渠道
  • 怎么用wordpress做网站如何做市场推广方案
  • 北斗手表官方网站windows优化大师最新版本
  • 读网站建设一定要买电脑实践吗网站seo搜索引擎的原理是什么
  • 国家域名备案查询深圳seo推广
  • 全国网站制作前十名十大经典广告营销案例
  • 网站 易用性原则百度的seo排名怎么刷
  • 做网站选云服务器内核创建网站需要多少资金
  • 重庆网站公司培训体系包括四大体系
  • 网站建设套餐电话今天nba新闻最新消息
  • 第四章第二节网站建设的教学设计郑州做网站推广电话
  • 做商城网站哪里好中国企业100强
  • 做网站的版式会侵权吗如何在手机上开自己的网站
  • 长春营销型网站设计抚州网站seo
  • 商务网站建设毕业设计模板下载直播营销策划方案范文
  • 轻松筹 做的网站价格昆明网络推广
  • 网站seo多少钱google推广教程
  • plone网站开发aso关键词优化计划
  • 上海的网站名百度推广开户2400
  • 长沙网站开发智投百度做广告效果怎么样