Skip to content

Commit

Permalink
add media_list get and free implement.
Browse files Browse the repository at this point in the history
  • Loading branch information
Jackarain committed May 17, 2012
1 parent a9d2819 commit 1d8c066
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 17 deletions.
32 changes: 20 additions & 12 deletions avcore/avplayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,22 +108,30 @@ int avplayer::media_count()
return m_impl->play_list().size();
}

int avplayer::query_media_name(int index, char *name, int size)
int avplayer::media_list(char ***list, int *size)
{
std::map<std::string, std::string> mlist = m_impl->play_list();
std::map<std::string, std::string>::iterator finder;
for (mlist.begin() = finder; finder != mlist.end(); finder++)

*size = mlist.size();
char **temp = new char*[*size];

int n = 0;
for (std::map<std::string, std::string>::iterator i = mlist.begin();
i != mlist.end(); i++)
{
if (index == 0)
{
if (finder->second.length() + 1 > size)
return finder->second.length() + 1;
strncpy(name, finder->second.c_str(), size);
return 0;
}
index--;
char *file_name = strdup(i->second.c_str());
temp[n] = file_name;
}
return -1;
*list = temp;

return*size;
}

void avplayer::free_media_list(char **list, int size)
{
for (int i = 0; i < size; i++)
free(list[i]);
delete[] list;
}

HWND avplayer::get_wnd()
Expand Down
18 changes: 13 additions & 5 deletions avcore/avplayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,19 @@ class EXPORT_API avplayer
// 返回当前播放列表中的媒体文件数.
int media_count();

// 返回播放列表index位置的媒体文件名.
// 参数name应该在外部分配内存, 通过size参数传入分配的
// 内存大小. 成功返回0, 返回-1表示失败, 返回大于0表示
// name分配的内存不够, 返回值为index对应的文件名长度.
int query_media_name(int index, char *name, int size);
// 返回播放列表.
// 参数list在模块内分配内存, 通过size参数传出列表大小.
// @ example begin
// char **list;
// int size = 0;
// play->media_list(&list, &size);
// ...
// play->free_media_list(list, size);
// @ example end
int media_list(char ***list, int* size);

// 释放播放列表的分配的内存资源.
void free_media_list(char **list, int size);

// 返回当前窗口句柄.
HWND get_wnd();
Expand Down

0 comments on commit 1d8c066

Please sign in to comment.