1
0

sseeker.cpp 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. #include <precomp.h>
  2. #include "sseeker.h"
  3. #include <api/script/scriptmgr.h>
  4. #include <api/core/api_core.h>
  5. #define SSeeker_TIMER_POS 1
  6. #define SSEEKER_INTERVAL 500
  7. const wchar_t seekBarXuiStr[] = L"SeekBar"; // This is the xml tag
  8. char seekBarXuiSvcName[] = "SeekBar xui object"; // this is the name of the xuiservice
  9. XMLParamPair SSeeker::params[] = {
  10. {SSEEKER_SETINTERVAL, L"INTERVAL"},
  11. };
  12. SSeeker::SSeeker() {
  13. setDrawOnBorders(TRUE);
  14. status = STOP;
  15. update_interval = SSEEKER_INTERVAL;
  16. locked = 0;
  17. xuihandle = newXuiHandle();
  18. CreateXMLParameters(xuihandle);
  19. setLimits(0, 65535);
  20. }
  21. void SSeeker::CreateXMLParameters(int master_handle)
  22. {
  23. //SSEEKER_PARENT::CreateXMLParameters(master_handle);
  24. int numParams = sizeof(params) / sizeof(params[0]);
  25. hintNumberOfParams(xuihandle, numParams);
  26. for (int i = 0;i < numParams;i++)
  27. addParam(xuihandle, params[i], XUI_ATTRIBUTE_IMPLIED);
  28. }
  29. SSeeker::~SSeeker() {
  30. killTimer(SSeeker_TIMER_POS);
  31. WASABI_API_MEDIACORE->core_delCallback(0, this);
  32. }
  33. int SSeeker::setXuiParam(int _xuihandle, int attribid, const wchar_t *name, const wchar_t *strval) {
  34. if (xuihandle != _xuihandle) return SSEEKER_PARENT::setXuiParam(_xuihandle, attribid, name, strval);
  35. switch (attribid) {
  36. case SSEEKER_SETINTERVAL:
  37. if ((update_interval = WTOI(strval)) <= 20)
  38. update_interval = SSEEKER_INTERVAL;
  39. break;
  40. default:
  41. return 0;
  42. }
  43. return 1;
  44. }
  45. int SSeeker::onInit() {
  46. SSEEKER_PARENT::onInit();
  47. timerCallback(SSeeker_TIMER_POS);
  48. setTimer(SSeeker_TIMER_POS, update_interval);
  49. WASABI_API_MEDIACORE->core_addCallback(0, this);
  50. return 1;
  51. }
  52. int SSeeker::onSetFinalPosition() {
  53. SSEEKER_PARENT::onSetFinalPosition();
  54. if (WASABI_API_MEDIACORE->core_getPosition(0) == -1) return 1;
  55. int pos = getSliderPosition(); // get slider pos
  56. int len = WASABI_API_MEDIACORE->core_getLength(0);
  57. int corepos = (int)(((double)pos * (double)len) / 65535.f);
  58. WASABI_API_MEDIACORE->core_setPosition(0,corepos);
  59. return 1;
  60. }
  61. void SSeeker::timerCallback(int id) {
  62. switch (id) {
  63. case SSeeker_TIMER_POS: {
  64. if (getSeekStatus()) return;
  65. int playpos = WASABI_API_MEDIACORE->core_getPosition(0);
  66. int len = WASABI_API_MEDIACORE->core_getLength(0);
  67. if (playpos < 0 || len <= 0) {
  68. setVisible(0);
  69. status=STOP;
  70. return;
  71. }
  72. int newpos = (int)(((double)playpos / (double)len) * 65535.f);
  73. if (getSliderPosition() != newpos) {
  74. setPosition(newpos, 0);
  75. onPostedPosition(newpos / scriptDivisor());
  76. }
  77. if (len > 0 && !isVisible()) {
  78. status=PLAY;
  79. setVisible(1);
  80. }
  81. }
  82. break;
  83. default:
  84. SSEEKER_PARENT::timerCallback(id);
  85. }
  86. }
  87. int SSeeker::corecb_onStarted() {
  88. timerCallback(SSeeker_TIMER_POS);
  89. return 0;
  90. }
  91. int SSeeker::corecb_onStopped() {
  92. timerCallback(SSeeker_TIMER_POS);
  93. return 0;
  94. }
  95. int SSeeker::corecb_onSeeked(int newpos) {
  96. timerCallback(SSeeker_TIMER_POS);
  97. return 0;
  98. }
  99. void SSeeker::lock() {
  100. if (locked) return;
  101. locked = 1;
  102. WASABI_API_MEDIACORE->core_delCallback(0, this);
  103. }
  104. void SSeeker::unlock() {
  105. if (!locked) return;
  106. locked = 0;
  107. WASABI_API_MEDIACORE->core_addCallback(0, this);
  108. }