Slider not working properly in a dialog MFC.?
Hi,
I have a slider control on a dialog box. I am playing a video file and slider moves according to the video elapsed. Suppose I have set the slider range to 100. Now till some point say 90, the slider moves to the point wherever I click the mouse. but at the last point in between some range say 90 - 100 (to the end of the slider), if I click the mouse button anywhere, slider jumps to the end.
I am using a TimeLine control where user can add more than 1 video (1, 2, 4, 8, 10 , 50 etc......), If I use only one video, slider moves as per the video progression.....Issue arises when I add more than 1 video and click on the start button, slider starts moving....Now when I drag the slider to any position or I click the mouse button anywhere on the slider control, slider thumb moves to that position and immediately jumps back to some other position. This is the Issue, I am facing.
Can anybody share some sample code where slider is moving with the video showing the progress of the video.
I want to implement a functionality similar to VLC player. Wherever user clicks the mouse, slider moves to that point.
Any help will be appreciated.
Regards,
Mbatra
Re: Slider not working properly in a dialog MFC.?
1. I have no idea what TimeLine control is...
2. How do you handle slider control position while playing movie?
3. How do you handle the slider control position changing by user?
Re: Slider not working properly in a dialog MFC.?
Quote:
Originally Posted by
Mbatra
but at the last point in between some range say 90 - 100 (to the end of the slider), if I click the mouse button anywhere, slider jumps to the end.
Sounds like you don't take thumb width into account when calculating position to jump to.
Quote:
slider thumb moves to that position and immediately jumps back to some other position.
This looks like you have some mechanism that updates position by current video. And if you do not stop video playback when clicking thumb, the mechanism will return the thumb back to real video position.
Quote:
I want to implement a functionality similar to VLC player. Wherever user clicks the mouse, slider moves to that point.
You should provide your code, compilable, simplified as much as possible, but still replicating your issues, and maybe we'll figure something out.
Re: Slider not working properly in a dialog MFC.?
Hi Igor,
Yes you are right,
"This looks like you have some mechanism that updates position by current video. And if you do not stop video playback when clicking thumb, the mechanism will return the thumb back to real video position."
This is what I am doing, I don't stop video playback while clicking thumb.
Below is the code I am using ....
void CEditVideoPage::OnStartEVTimer()
{
nVID = 27188;
mStartTime = CTime::GetCurrentTime();
m_VideoPlay = SetTimer(nVID, 1000, NULL);
}
void CEditVideoPage::OnStopEVTimer()
{
rmp = 0;
// munish added
if (m_VideoPlay != 0)
{
KillTimer(nVID);
m_VideoPlay = 0;
}
// munish added
}
void CEditVideoPage::OnTimer(UINT_PTR nIDEvent)
{
if( nIDEvent == nVID)
{
if( !(m_EditSlider.svalue) ) // m_EditSlider.svalue is set to true SliderCtrlEx class where OnLButtonDown is overridden
{
ReleasePos = spansec * (100 / EVideolength);
m_EditSlider.SetPos((ReleasePos));
UpdateData(false);
}
}
CPropertyPage::OnTimer(nIDEvent);
}
void CEditVideoPage::OnReleasedcaptureEditslider(NMHDR *pNMHDR, LRESULT *pResult)
{
m_EditSlider.svalue = false; // here set this to false m_EditSlider.svalue
ReleasePos = m_EditSlider.GetPos();
int ret = ReleasePos * (EVideolength / 100);
int h = ret / 3600;
ret = ret % 3600;
int m = ret / 60;
ret = ret % 60;
int s = ret;
CTimeSpan b;
CTime y = CTime::GetCurrentTime();
y = y - (CTimeSpan)ret;
mStartTime = y;
REFERENCE_TIME Pos = 0;
Pos = ret * 10000000;
pMediaSeekingEV->SetPositions(&Pos, AM_SEEKING_AbsolutePositioning, NULL, AM_SEEKING_NoPositioning);
*pResult = 0;
}
void CEditVideoPage::PauseEVTimer()
{
onPauseTime = CTime::GetCurrentTime();
KillTimer(nVID);
m_VideoPlay = 0;
}
// munish added - end
void CEditVideoPage::PausePreview()
{
if(m_pEditViewMC != 0)
{
PauseEVTimer();
HRESULT hr = m_pEditViewMC->Pause();
if(hr == S_FALSE)
{
FILTER_STATE fs;
m_pEditViewMC->GetState(10, (OAFilterState*)&fs);
}
}
}
and this one in // CSliderCtrlEx class where OnLButtonDown is overridden
void CSliderCtrlEx::OnLButtonDown(UINT nFlags, CPoint point)
{
svalue = true;
CRect rectClient;
GetClientRect(rectClient);
CRect rectChannel;
GetChannelRect(rectChannel);
int nPos = (GetRangeMax() - GetRangeMin()) *
(point.x - rectClient.left - rectChannel.left) /
(rectChannel.right - rectChannel.left);
SetPos(nPos);
CSliderCtrl::OnLButtonDown(nFlags, point);
}
plz let me know if u still need some more explanation.
Regards,
Mbatra
Re: Slider not working properly in a dialog MFC.?
Could you start using code tags?
Re: Slider not working properly in a dialog MFC.?
Quote:
void CSliderCtrlEx::OnLButtonDown(UINT nFlags, CPoint point)
{
svalue = true;
CRect rectClient;
GetClientRect(rectClient);
CRect rectChannel;
GetChannelRect(rectChannel);
int nPos = (GetRangeMax() - GetRangeMin()) *
(point.x - rectClient.left - rectChannel.left) /
(rectChannel.right - rectChannel.left);
SetPos(nPos);
CSliderCtrl::OnLButtonDown(nFlags, point);
}
As I said, you do not take thumb width into account when calculating target position.
I believe I already provided this code to you:
Code:
void CSliderCtrlEx::OnLButtonDown(UINT nFlags, CPoint point)
{
CRect rc, trc;
GetChannelRect(rc);
GetThumbRect(trc);
rc.InflateRect(0, (trc.Height() - rc.Height())/2);
if (!PtInRect(rc, point))
return;
TRACE("!\n");
LONG range = GetRangeMax();
LONG pos = point.x - rc.left - trc.Width()/2;
LONG width = rc.Width() - trc.Width();
SetPos(int(DOUBLE(pos) * range / width + 0.5));
CSliderCtrl::OnLButtonDown(nFlags, point);
}
Re: Slider not working properly in a dialog MFC.?
Quote:
This is what I am doing, I don't stop video playback while clicking thumb.
And? What is your logic behind this?
Re: Slider not working properly in a dialog MFC.?
Hi Igor,
actually the logic was when user clicks anywhere on the slider, thumb moves to that position. But if user clicks on the thumb and holds for some seconds and then drags the slider to some position, preview should not stop, rather when user will release the thumb, I will seek the video by that much time.
So I didn't stop the preview.
Re: Slider not working properly in a dialog MFC.?
Thanks Igor, its working fine now.
Now I have one more issue, I am using a Timeline into which user can add more than one videos at a time.
Now when I start the playing the videos, It starts playing one by one......taking one video at a time from the Timeline.
You can consider timeline as a list of video placed one after the other. I am storing that into a vector.
Now in this case slider is working fine if I play only one video, but if I add more than one video and click on the play button, videos start playing.
Then when I click anywhere on the slider, it jumps back and forth between the cursor. Can you please suggest me any logic for this.
Regards,
Mbatra
Re: Slider not working properly in a dialog MFC.?
Quote:
Originally Posted by
Mbatra
actually the logic was when user clicks anywhere on the slider, thumb moves to that position.
Actually it was not. As I understand, when user clicks on the slider, the target position is determined, and communicated to media seeker. The media seeker makes media to change its presentation time (position), and the position is communicated back to slider, and its thumb finally appears where it was supposed to be (where the original click was). This is the logic behind, as I asked you about internals but not about what it seems like to user.
Quote:
But if user clicks on the thumb and holds for some seconds and then drags the slider to some position, preview should not stop, rather when user will release the thumb, I will seek the video by that much time.
So I didn't stop the preview.
So please, having in mind the analysis above, explain your internal logic, why you don't stop the playback and how you suppose this to work the way you want.
Re: Slider not working properly in a dialog MFC.?
Hi,
This is the code in which I am taking the slider value when user clicks on the thumb and then calcite the time by which I have to seek the media forward/backward.
<code>
void CCapturePage::OnReleasedcaptureCaptureslider(NMHDR *pNMHDR, LRESULT *pResult)
{
m_CaptureSlider.svalue = false;
ReleasePos = m_CaptureSlider.GetPos();
int ret = ReleasePos * (videolength / 100);
int h = ret / 3600;
ret = ret % 3600;
int m = ret / 60;
ret = ret % 60;
int s = ret;
CTimeSpan b;
CTime y = CTime::GetCurrentTime();
y = y - (CTimeSpan)ret;
mStartTime = y;
REFERENCE_TIME Pos = 0;
Pos = ret * 10000000;
pMediaSeeking->SetPositions(&Pos, AM_SEEKING_AbsolutePositioning, NULL, AM_SEEKING_NoPositioning);
*pResult = 0;
}
</code>
Re: Slider not working properly in a dialog MFC.?
Hi Igor,
Can you share some sample code where user clicks the slider and video progresses by that much amount of time.
Regards,
Mbatra
Re: Slider not working properly in a dialog MFC.?
Quote:
Originally Posted by
Mbatra
This is the code in which I am taking the slider value when user clicks on the thumb
Well, shooting at me with arbitrary code snippets won't work. I've asked you to explain your design. In plain English please. C++ will enter the scene a bit later.
Quote:
Can you share some sample code
No, just because preparing such sample is not that simple, and you know, I have not much free time. Why don't you post your simplified code, as you were already suggested, several times I believe?
Re: Slider not working properly in a dialog MFC.?
Please, as you have requested, use code tags. These use [] and not <>. The easiest way is to Go Advanced, select the code and click '#'.