WIndows Phone 7中Mediaelement中的Seekbar功能 [英] Seekbar functionality in Mediaelement in WIndows Phone 7

查看:70
本文介绍了WIndows Phone 7中Mediaelement中的Seekbar功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我正在制作媒体播放器。我必须为玩家保留搜索栏。我正在使用滑块。任务是滑块应该与媒体一起移动。但问题是它只是卡在那里而不是移动。我的代码在这里



xaml



Hi,

I am working on media player . I have to keep seekbar for the player. I am using slider . Task is the slider should move with media .But problem is that it is just stuck there and not moving. My code goes here

xaml

<MediaElement Height="Auto" HorizontalAlignment="Stretch" Margin="-12,-45,0,0" Name="mediaElement1"  CurrentStateChanged="mediaElement1_CurrentStateChanged"

 VerticalAlignment="Stretch" Width="Auto" AutoPlay="True" Loaded="mediaElement1_Loaded" MediaEnded="mediaElement1_MediaEnded" MediaOpened="mediaElement1_MediaOpened" />
            <Slider Name="timelineSlider" Margin="5,348,5,5" ValueChanged="timelineSlider_ValueChanged" />





xaml.cs





xaml.cs

private void mediaElement1_MediaOpened(object sender, RoutedEventArgs e)
        {
            timelineSlider.Maximum = mediaElement1.NaturalDuration.TimeSpan.TotalMilliseconds;
        }

        private void timelineSlider_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
        {
            int SliderValue = (int)timelineSlider.Value;
            TimeSpan ts = new TimeSpan(0, 0, 0, 0, SliderValue);
            mediaElement1.Position = ts;
        }





任何人都可以建议我解决这个问题...提前谢谢



can anyone suggest me solving this...thanks in advance

推荐答案

首先我建议将这些属性添加到MediaElement声明中



问题形成了你玩什么样的媒体??

它是缓冲的吗?或者它只是来自档案?

根据回答,可以应用默认媒体行为



好​​吧,如果没有缓冲尝试做下一个:



Hi , first of all i would suggest to add such propertsion to MediaElement declaration

And the question is formed what kind of media did you play ??
Is it a buffered ? or it is just from file ?
According to answer , default media behaviors could be applied

Ok , if it not buffered try to do the next:

<slider x:name="timelineSlider" thumb.dragstarted="seekBar_DragStarted" thumb.dragcompleted="seekBar_DragCompleted">







private void mediaElement1_MediaOpened(object sender, RoutedEventArgs e)
 {
    TimeSpan ts = mediaElement1.NaturalDuration.TimeSpan;
    timelineSlider.Maximum = ts.TotalSeconds;
    timelineSlider.SmallChange = 1;
    timelineSlider.LargeChange = Math.Min(10, ts.Seconds / 10);
 }







private void seekBar_DragCompleted(object sender, DragCompletedEventArgs e)
{
    mediaElement1.Position = TimeSpan.FromSeconds(timelineSlider.Value);
}


这篇关于WIndows Phone 7中Mediaelement中的Seekbar功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆