📄 mediaplaylistoperatenew.c
字号:
/****************************************************************************************************
*****************************************************************************************************
COPYRIGHT (c) 2007 BY ROCK-CHIP FUZHOU
-- ALL RIGHTS RESERVED --
File Name: MediaFavoOperateNew.c
Author: Peng Huacheng
Created: 07-12-03
Modified:
Revision:
****************************************************************************************************
****************************************************************************************************/
#if ((defined(BOARD)) || defined(ROCK_FS))
#include <stdio.h>
#include <stdlib.h>
#include "include.h"
#include "System.h"
#ifdef _MEIDA_SORT_NEW
#ifndef _PLAYLIST_OPERATE_
#define _PLAYLIST_OPERATE_
#include "MediaPlaylistGloableNew.h"
#include "..\MediaInfoGet\MediaInfoGetStructNew.h"
#include "..\MediaInfoGet\MediaBroGloableNew.h"
#ifdef BOARD
#include "..\AUDIO\AudioControl\AudioControl.h"
extern INT16U AudioPlayState;
#endif
void TrySavePlaylitInfo(void);
void PlaylistEditConfirm(UINT16 PlayListNo);
void PlaylistEditCancle(UINT16 PlayListNo);
/*----------------------------------------------------------------------
Name : AddFileToPlaylist
Desc : 增加一个文件至播放列表
Params: pMediaInfo:媒体库文件信息结构体 PlayListNo:收藏夹编号
Author: phc
Date : 07-12-03
----------------------------------------------------------------------*/
UINT32 AddFileToPlaylist(FILE_MEDIAINFO_STRUCT *pMediaInfo, UINT16 PlayListNo)
{
char *pTemp = NULL;
FS_FILE* fFile = NULL;
PLAYLIST_INFO_STRUCT PlaylistStruct; // 播放列表文件保存结构体
UINT16 *pPlaylistNumTemp = NULL;
PLAYLIST_INFO_STRUCT *pPlaylistInfoTemp = NULL;
UINT16 i = 0;
RKSemObtain(&PlayListUseSem);
//PlayListInfo[PlayListNo].BusyFlag= 1; // 表示收藏夹内存使用中,无需将信息写入文件
if (PlayListInfo[PlayListNo].FileNum >= FILE_NUM_PER_PLAYLIST)
{
//PlayListInfo[PlayListNo].BusyFlag = 0;
RkSemRelease(&PlayListUseSem);
return FALSE; // 收藏夹容量已满
}
if (PlayListInfo[PlayListNo].pPlaylistMem == NULL) // 收藏夹信息尚未调入内存则先调入
{
//PlayListInfo[PlayListNo].pPlaylistMem = (char*)malloc(sizeof(PLAYLIST_INFO_STRUCT)*FILE_NUM_PER_PLAYLIST); // 申请存放收藏夹信息内存
PlayListInfo[PlayListNo].pPlaylistMem = (char*)malloc(PLAYLIST_SIZE_PER_FILE); // 申请存放收藏夹信息内存
if (PlayListInfo[PlayListNo].pPlaylistMem == NULL)
{
//PlayListInfo[PlayListNo].BusyFlag = 0;
RkSemRelease(&PlayListUseSem);
return FALSE;
}
//RKmemset(PlayListInfo[PlayListNo].pPlaylistMem, 0, sizeof(PLAYLIST_INFO_STRUCT)*FILE_NUM_PER_PLAYLIST);
RKmemset(PlayListInfo[PlayListNo].pPlaylistMem, 0, PLAYLIST_SIZE_PER_FILE);
if (PlayListInfo[PlayListNo].FileNum) // 当收藏夹文件有内容时,先读出原有收藏夹信息
{
fFile = FS_fopen(PlayListInfo[PlayListNo].pPath, "r");
if (fFile == NULL)
{
free(PlayListInfo[PlayListNo].pPlaylistMem);
PlayListInfo[PlayListNo].pPlaylistMem = NULL;
//PlayListInfo[PlayListNo].BusyFlag = 0;
RkSemRelease(&PlayListUseSem);
return FALSE; // 内存申请失败
}
FS_fread(PlayListInfo[PlayListNo].pPlaylistMem, sizeof(PLAYLIST_INFO_STRUCT), PlayListInfo[PlayListNo].FileNum + 1, fFile);
FS_fclose(fFile);
}
}
/* 判断是否已经存在播放列表中 */
for (i = 0;i < PlayListInfo[PlayListNo].FileNum;i++)
{
pPlaylistInfoTemp = (PLAYLIST_INFO_STRUCT*)(&PlayListInfo[PlayListNo].pPlaylistMem[(i+1)*sizeof(PLAYLIST_INFO_STRUCT)]);
if ((0 == RKstrcmp(pMediaInfo->Path, pPlaylistInfoTemp->Path)) && (0 == RKstrcmp(pMediaInfo->Name, pPlaylistInfoTemp->Name)))
{
break;
}
}
if (i >= PlayListInfo[PlayListNo].FileNum)
{
pTemp = &PlayListInfo[PlayListNo].pPlaylistMem[(PlayListInfo[PlayListNo].FileNum + 1) * sizeof(PLAYLIST_INFO_STRUCT)];
RKmemset(&PlaylistStruct, 0, sizeof(PLAYLIST_INFO_STRUCT));
RKmemcpy(PlaylistStruct.FileName, pMediaInfo->ListName1, CHAR_NUM_PER_FILE_NAME*sizeof(UINT16));
RKmemcpy(PlaylistStruct.Name, pMediaInfo->Name, 11);
RKmemcpy(PlaylistStruct.Path, pMediaInfo->Path, FS_MAX_PATH_LEN);
RKmemcpy(pTemp, &PlaylistStruct, sizeof(PLAYLIST_INFO_STRUCT));
PlayListInfo[PlayListNo].FileNum++;// = PlayListInfo[PlayListNo].FileNum + 1;
pPlaylistNumTemp = (UINT16*)(&PlayListInfo[PlayListNo].pPlaylistMem[0]);
*pPlaylistNumTemp = PlayListInfo[PlayListNo].FileNum; // 将统计信息写到加密信息文件头中
}
//PlayListInfo[PlayListNo].BusyFlag = 0;
RkSemRelease(&PlayListUseSem);
return TRUE;
}
/*----------------------------------------------------------------------
Name : AddGroupFileToPlaylist
Desc : 增加一组文件信息到播放列表中
Params: pMediaInfo:媒体库文件信息结构体 GroupType:组类别 PlayListNo:播放列表号
Return:
Author: phc
Date : 07-12-03
----------------------------------------------------------------------*/
UINT32 AddGroupFileToPlaylist(FILE_MEDIAINFO_STRUCT *pMediaInfo, UINT16 GroupType , UINT16 PlayListNo)
{
FS_FILE* fFile = NULL;
MediaInfoGetCallback MediaInfoGet;
FILE_MEDIAINFO_STRUCT AddInfo;
UINT16 i;
if ((PlayListInfo[PlayListNo].FileNum + pMediaInfo->ChildItemNum) >= FILE_NUM_PER_PLAYLIST)
{
//PlayListInfo[PlayListNo].BusyFlag = 0;
return FALSE; // 收藏夹容量已满
}
switch (GroupType)
{
case ARTIST_MEDIA_PLAY_TYPE:
MediaInfoGet = GetMediaArtistMusicInfo;
break;
case ALBUM_MEDIA_PLAY_TYPE:
MediaInfoGet = GetMediaAlbumMusicInfo;
break;
case GENRE_MEDIA_PLAY_TYPE:
MediaInfoGet = GetMediaGenreMusicInfo;
break;
default:
break;
}
if (PlayListInfo[PlayListNo].pPlaylistMem == NULL) // 收藏夹信息尚未调入内存则先调入
{
PlayListInfo[PlayListNo].pPlaylistMem = (char*)malloc(PLAYLIST_SIZE_PER_FILE); // 申请存放收藏夹信息内存
if (PlayListInfo[PlayListNo].pPlaylistMem == NULL)
{
//PlayListInfo[PlayListNo].BusyFlag = 0;
return FALSE;
}
RKmemset(PlayListInfo[PlayListNo].pPlaylistMem, 0, PLAYLIST_SIZE_PER_FILE);
if (PlayListInfo[PlayListNo].FileNum) // 当收藏夹文件有内容时,先读出原有收藏夹信息
{
fFile = FS_fopen(PlayListInfo[PlayListNo].pPath, "r");
if (fFile == NULL)
{
free(PlayListInfo[PlayListNo].pPlaylistMem);
PlayListInfo[PlayListNo].pPlaylistMem = NULL;
//PlayListInfo[PlayListNo].BusyFlag = 0;
return FALSE; // 内存申请失败
}
FS_fread(PlayListInfo[PlayListNo].pPlaylistMem, sizeof(PLAYLIST_INFO_STRUCT), PlayListInfo[PlayListNo].FileNum + 1, fFile);
FS_fclose(fFile);
}
}
for (i = 0; i < pMediaInfo->ChildItemNum; i++)
{
MediaInfoGet(&AddInfo, i, pMediaInfo->SorIndex);
AddFileToPlaylist(&AddInfo, PlayListNo);
}
return TRUE;
}
/*----------------------------------------------------------------------
Name : DelPlaylistFileInfo
Desc : 删除播放列表一个文件信息
Params: DelNo:删除的文件,注:以0开始计数 PlayListNo:播放列表号
Author: phc
Date : 07-12-03
----------------------------------------------------------------------*/
UINT32 DelPlaylistFileInfo(UINT16 DelNo, UINT16 PlayListNo)
{
char *pTemp1 = NULL;
char *pTemp2 = NULL;
FS_FILE* fFile = NULL;
UINT16 *pPlaylistNumTemp = NULL;
if (PlayListInfo[PlayListNo].FileNum == 0)
return TRUE;
RKSemObtain(&PlayListUseSem);
//PlayListInfo[PlayListNo].BusyFlag = 1; // 表示收藏夹内存使用中,无需将信息写入文件
if (PlayListInfo[PlayListNo].pPlaylistMem == NULL) // 收藏夹信息尚未调入内存则先调入
{
fFile = FS_fopen(PlayListInfo[PlayListNo].pPath, "r");
if (fFile == NULL)
{
//PlayListInfo[PlayListNo].BusyFlag = 0;
RkSemRelease(&PlayListUseSem);
return FALSE; // 内存申请失败
}
PlayListInfo[PlayListNo].pPlaylistMem = (char*)malloc(PLAYLIST_SIZE_PER_FILE); // 申请存放收藏夹信息内存
if (PlayListInfo[PlayListNo].pPlaylistMem == NULL)
{
//PlayListInfo[PlayListNo].BusyFlag = 0;
RkSemRelease(&PlayListUseSem);
return FALSE;
}
RKmemset(PlayListInfo[PlayListNo].pPlaylistMem, 0, PLAYLIST_SIZE_PER_FILE);
FS_fread(PlayListInfo[PlayListNo].pPlaylistMem, sizeof(PLAYLIST_INFO_STRUCT), PlayListInfo[PlayListNo].FileNum + 1, fFile);
FS_fclose(fFile);
}
pTemp1 = &PlayListInfo[PlayListNo].pPlaylistMem[(DelNo+1)*sizeof(PLAYLIST_INFO_STRUCT)];
pTemp2 = &PlayListInfo[PlayListNo].pPlaylistMem[(DelNo+2)*sizeof(PLAYLIST_INFO_STRUCT)];
PlayListInfo[PlayListNo].FileNum--;// = PlayListInfo[PlayListNo].FileNum - 1;
pPlaylistNumTemp = (UINT16*)(&PlayListInfo[PlayListNo].pPlaylistMem[0]);
*pPlaylistNumTemp = PlayListInfo[PlayListNo].FileNum; // 将统计信息写到加密信息文件头中
RKmemcpy(pTemp1, pTemp2, sizeof(PLAYLIST_INFO_STRUCT)*(PlayListInfo[PlayListNo].FileNum - DelNo));
RKmemset(&PlayListInfo[PlayListNo].pPlaylistMem[(PlayListInfo[PlayListNo].FileNum + 1)*sizeof(PLAYLIST_INFO_STRUCT)], 0, sizeof(PLAYLIST_INFO_STRUCT));
//PlayListInfo[PlayListNo].BusyFlag = 0;
RkSemRelease(&PlayListUseSem);
return TRUE;
// return DelMediaFileInfo(pPath, pTotalNum, DelNo, (UINT16)(PlayListInfo[PlayListNo].FileNum-DelNo-1));
}
/*----------------------------------------------------------------------
Name : ClearFavoAll
Desc : 清空播放列表
Params: PlayListNo:播放列表号
Author: phc
Date : 07-12-03
----------------------------------------------------------------------*/
UINT32 ClearFavoAll(UINT16 PlayListNo)
{
if (PlayListInfo[PlayListNo].FileNum == 0)
return TRUE;
RKSemObtain(&PlayListUseSem);
//PlayListInfo[PlayListNo].BusyFlag = 1;
#if 0
PlayListInfo[PlayListNo].FileNum = 0;
if (PlayListInfo[PlayListNo].pPlaylistMem != NULL)
{
free(PlayListInfo[PlayListNo].pPlaylistMem);
PlayListInfo[PlayListNo].pPlaylistMem = NULL;
}
#else
if (PlayListInfo[PlayListNo].pPlaylistMem == NULL) // 收藏夹信息尚未调入内存则先调入
{
PlayListInfo[PlayListNo].pPlaylistMem = (char*)malloc(PLAYLIST_SIZE_PER_FILE); // 申请存放收藏夹信息内存
if (PlayListInfo[PlayListNo].pPlaylistMem == NULL)
{
//PlayListInfo[PlayListNo].BusyFlag = 0;
RkSemRelease(&PlayListUseSem);
return FALSE;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -