CPI_Player_Callbacks.c
上传用户:tuheem
上传日期:2007-05-01
资源大小:21889k
文件大小:4k
源码类别:

多媒体编程

开发平台:

Visual C++

  1. #include "stdafx.h"
  2. #include "globals.h"
  3. #include "CPI_Player.h"
  4. #include "CPI_Playlist.h"
  5. #include "CPI_PlaylistItem.h"
  6. #define CP_SYNCCOOKIE_DESTROY 301
  7. void CPI_Player_cb_OnStreamInfo(CP_HPLAYER hPlayer, const CPs_FileInfo* pInfo)
  8. {
  9.     globals.main_long_track_duration = pInfo->m_iFileLength_Secs;
  10.     if(pInfo->m_iBitRate_Kbs)
  11.         _itoa(pInfo->m_iBitRate_Kbs, globals.main_text_bitrate, 10);
  12.     else
  13.         globals.main_text_bitrate[0] = '';
  14.     if(pInfo->m_iFreq_Hz)
  15.         _itoa(pInfo->m_iFreq_Hz / 1000, globals.main_text_frequency, 10);
  16.     else
  17.         globals.main_text_frequency[0] = '';
  18.     main_draw_bitrate(windows.wnd_main);
  19.     main_draw_frequency(windows.wnd_main);
  20. }
  21. //
  22. void CPI_Player_cb_OnStreamOffset_Secs(CP_HPLAYER hPlayer, const int iTrackElapsedSeconds)
  23. {
  24.     globals.main_int_track_total_seconds = iTrackElapsedSeconds;
  25.     main_draw_time(windows.wnd_main);
  26. }
  27. //
  28. void CPI_Player_cb_OnStreamOffset_Range(CP_HPLAYER hPlayer, const int iTrackElapsed_Range)
  29. {
  30.     globals.main_int_track_position = iTrackElapsed_Range;
  31.     if(globals.m_bStreaming == TRUE)
  32.         main_draw_vu_from_value(windows.wnd_main, PositionSlider, globals.m_iStreamingPortion);
  33.     else
  34.         main_draw_vu_from_value(windows.wnd_main, PositionSlider, globals.main_int_track_position);
  35. }
  36. //
  37. void CPI_Player_cb_OnPlayerState(CP_HPLAYER hPlayer, const CPe_PlayerState enPlayerState)
  38. {
  39.     switch(enPlayerState)
  40.     {
  41.     case cppsEndOfStream:
  42.         {
  43.             CP_HPLAYLISTITEM hCurrent = CPL_GetActiveItem(globals.m_hPlaylist);
  44.             if(options.repeat_playlist == FALSE
  45.                     && options.shuffle_play == FALSE
  46.                     && (hCurrent == NULL || CPLI_Next(hCurrent) == NULL) )
  47.             {
  48.                 CPI_Player__BlockMessagesUntilEndOfStream(hPlayer);
  49.                 if(options.auto_exit_after_playing == TRUE)
  50.                     CPI_Player__SendSyncCookie(hPlayer, CP_SYNCCOOKIE_DESTROY);
  51.             }
  52.             else
  53.             {
  54.                 if(options.seconds_delay_after_track > 0)
  55.                     SetTimer(windows.wnd_main, CPC_TIMERID_INTERTRACKDELAY, 2000 + (options.seconds_delay_after_track * 1000), NULL);
  56.                 else
  57.                     CPL_PlayItem(globals.m_hPlaylist, FALSE, pmNextItem);
  58.             }
  59.         }
  60.         break;
  61.     case cppsPlaying:
  62.     case cppsPaused:
  63.         globals.m_enPlayerState = enPlayerState;
  64.         main_draw_controls_all(windows.wnd_main);
  65.         break;
  66.     case cppsStopped:
  67.         globals.m_enPlayerState = enPlayerState;
  68.         memset(globals.main_text_bitrate, 0, sizeof(globals.main_text_bitrate));
  69.         memset(globals.main_text_frequency, 0, sizeof(globals.main_text_frequency));
  70.         main_draw_bitrate(windows.wnd_main);
  71.         main_draw_frequency(windows.wnd_main);
  72.         globals.main_int_track_total_seconds = 0;
  73.         main_draw_time(windows.wnd_main);
  74.         globals.main_int_track_position = 0;
  75.         main_draw_vu_from_value(windows.wnd_main, PositionSlider, globals.main_int_track_position);
  76.         main_draw_controls_all(windows.wnd_main);
  77.         break;
  78.     }
  79. }
  80. //
  81. void CPI_Player_cb_OnSyncCookie(CP_HPLAYER hPlayer, const int iCookie)
  82. {
  83.     if(iCookie == CP_SYNCCOOKIE_DESTROY)
  84.         DestroyWindow(windows.wnd_main);
  85. }
  86. //
  87. void CPI_Player_cb_OnVolumeChange(CP_HPLAYER hPlayer, const int iNewVolume)
  88. {
  89.     globals.m_iVolume = iNewVolume;
  90.     main_draw_vu_from_value(windows.wnd_main, VolumeSlider, iNewVolume);
  91. }
  92. //
  93. void CPI_Player_cb_OnStreamStateChange(CP_HPLAYER hPlayer, const BOOL bStreaming, const int iBufferUsagePercent)
  94. {
  95.     const int iRange = Skin.Object[PositionSlider].maxw ? Skin.Object[PositionSlider].h : Skin.Object[PositionSlider].w;
  96.     globals.m_bStreaming = bStreaming;
  97.     if(iRange)
  98.         globals.m_iStreamingPortion = (iBufferUsagePercent * iRange) / 100;
  99.     else
  100.         globals.m_iStreamingPortion = 0;
  101.     main_draw_vu_from_value(windows.wnd_main, PositionSlider, globals.m_iStreamingPortion);
  102. }
  103. //
  104. void CPI_Player_cb_OnEnumOutputDevice(CP_HPLAYER hPlayer, const char* pcDeviceName, const int iDeviceID)
  105. {
  106.     int iNewDeviceIDX;
  107.     iNewDeviceIDX = SendDlgItemMessage(windows.dlg_options, IDC_OUTPUT, CB_ADDSTRING, 0, (LPARAM)pcDeviceName);
  108.     SendDlgItemMessage(windows.dlg_options, IDC_OUTPUT, CB_SETITEMDATA, iNewDeviceIDX - 1, MAKELPARAM(iDeviceID,iDeviceID));
  109.     SendDlgItemMessage(windows.dlg_options, IDC_OUTPUT, CB_SETCURSEL, options.decoder_output_mode, 0);
  110. }