CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 14 of 14
  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 online now Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,395

    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.?

    Could you start using code tags?
    Best regards,
    Igor

  6. #6
    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

  7. #7
    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

  8. #8
    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.

  9. #9
    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

  10. #10
    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
    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.

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

  11. #11
    Join Date
    Nov 2009
    Posts
    24

    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>

  12. #12
    Join Date
    Nov 2009
    Posts
    24

    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

  13. #13
    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
    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.

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

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

    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