CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 14 of 14

Hybrid View

  1. #1
    Join Date
    Nov 2009
    Posts
    24

    Question 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
    Last edited by Mbatra; July 3rd, 2013 at 08:15 AM.

  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,398

    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?
    Victor Nijegorodov

  3. #3
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    6,620

    Re: Slider not working properly in a dialog MFC.?

    Quote Originally Posted by Mbatra View Post
    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.

    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.

    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.
    Best regards,
    Igor

  4. #4
    Join Date
    Nov 2009
    Posts
    24

    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

  5. #5
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    6,620

    Re: Slider not working properly in a dialog MFC.?

    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);
    }
    Best regards,
    Igor

  6. #6
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    6,620

    Re: Slider not working properly in a dialog MFC.?

    This is what I am doing, I don't stop video playback while clicking thumb.
    And? What is your logic behind this?
    Best regards,
    Igor

  7. #7
    Join Date
    Nov 2009
    Posts
    24

    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.

  8. #8
    Join Date
    Nov 2009
    Posts
    24

    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

  9. #9
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    6,620

    Re: Slider not working properly in a dialog MFC.?

    Could you start using code tags?
    Best regards,
    Igor

  10. #10
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,825

    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 '#'.
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++23 Compiler: Microsoft VS2022 (17.6.5)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured