Playlist.cpp
上传用户:lusi_8715
上传日期:2007-01-08
资源大小:199k
文件大小:3k
源码类别:

流媒体/Mpeg4/MP4

开发平台:

Visual C++

  1. /**************************************************************************************
  2.  *                                                                                    *
  3.  * This application contains code from OpenDivX and is released as a "Larger Work"    *
  4.  * under that license. Consistant with that license, this application is released     *
  5.  * under the GNU General Public License.                                              *
  6.  *                                                                                    *
  7.  * The OpenDivX license can be found at: http://www.projectmayo.com/opendivx/docs.php *
  8.  * The GPL can be found at: http://www.gnu.org/copyleft/gpl.html                      *
  9.  *                                                                                    *
  10.  * Copyright (c) 2001 - Project Mayo                                                  *
  11.  *                                                                                    *
  12.  * Authors: Damien Chavarria <adrc at projectmayo.com>                                *
  13.  *                                                                                    *
  14.  **************************************************************************************/
  15. #include "Playlist.h"
  16. Playlist::Playlist()
  17. {
  18. this->list             = NULL;
  19. this->nbr_items        = 0;
  20. this->current_position = -1;
  21. }
  22. Playlist::~Playlist()
  23. {
  24. }
  25. int Playlist::Clear()
  26. {
  27. this->nbr_items        = 0;
  28. this->current_position = -1;
  29. this->list             = NULL;
  30. return 1;
  31. }
  32. int Playlist::Reset() 
  33. {
  34. if(this->list != NULL) {
  35. this->current_position = 0;
  36. }
  37. return 1;
  38. }
  39. char *Playlist::GetItemAt(int i)
  40. {
  41. int index, j;
  42. list_t *node;
  43. if(this->list != NULL) {
  44. if( i < 0)
  45. return list->filename;
  46. if(i > this->nbr_items - 1)
  47. index = this->nbr_items - 1;
  48. else 
  49. index = i;
  50. node = this->list;
  51. for(j=0; j<index; j++) {
  52. node = node->next;
  53. }
  54. return node->filename;
  55. }
  56. return NULL;
  57. }
  58. int Playlist::Add(char *filename)
  59. {
  60. list_t *item;
  61. item = (list_t *) malloc(sizeof(list_t));
  62. item->filename = filename;
  63. item->next = this->list;
  64. this->list = item;
  65. this->nbr_items++;
  66. return 1;
  67. }
  68. char *Playlist::Previous()
  69. {
  70. if(this->list != NULL) {
  71. if(this->current_position == 0)
  72. return list->filename;
  73. this->current_position--;
  74. return GetItemAt(this->current_position);
  75. }
  76. return NULL;
  77. }
  78. char *Playlist::Next()
  79. {
  80. if(this->list != NULL) {
  81. if(this->current_position == this->nbr_items - 1)
  82. return GetItemAt(this->current_position);
  83. this->current_position++;
  84. return GetItemAt(this->current_position);
  85. }
  86. return NULL;
  87. }