2013-11-26 2 views
0

가져올 버튼을 미디어 요소와 연결하여 재생할 노래를 가져올 수 있습니다.레이블 및 슬라이더가있는 WPF의 미디어 요소 링크

  // Create OpenFileDialog 
     Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog(); 



     // Set filter for file extension and default file extension 
     dlg.DefaultExt = ".txt"; 
     dlg.Filter = "WAV Files (*.wav)|*.wav|MP3 Files (*.mp3)|*.mp3|MP4 Files (*.mp4)|*.mp4|WMA Files (*.wma)|*.wma|SWA (*.swa)|*.swa"; 


     // Display OpenFileDialog by calling ShowDialog method 
     Nullable<bool> result = dlg.ShowDialog(); 


     // Get the selected file name and display in a TextBox 
     if (result == true) 
     { 
      // Open document 
      meMedia1.Source = new Uri(dlg.FileName); 
      meMedia1.Play(); 
      //txtFileLocation.Text = filename; 

지금, 사운드 재생하지만 내가 원하는 그것이 얼마나 긴 노래로 읽을 수 있도록 그들이 노래도 슬라이더 위의 라벨의 일부를 생략 할 수 있도록 슬라이더를 연결합니다. 이것은 내 응용 프로그램이 지금 당신에게 아이디어를주는 모습입니다.

http://i.stack.imgur.com/sVtrd.png

감사합니다.

EDIT : 노래 위치를 변경하려고 시도했으나 여전히 노래의 중간 부분으로 건너 뛰면 노래의 시간으로 수동으로 이동합니다. 중간에 있으니 끝까지 갖고 싶습니다.

답변

0

한 가지 방법은 플레이어의 현재 위치에 슬라이더를 동기화하는 200-800ms마다 (업데이트 속도에 대한 선호도에 따라) 틱하는 DispatcherTimer를 만드는 것입니다. 그 코드는 다음과 비슷한 보일 수 있습니다 : 이것은 당신이 가정합니다

// In the class members area 
private DispatcherTimer _timer = null; 

// In your constructor/loaded method 
_timer = new DispatcherTimer(); 
_timer.Interval = TimeSpan.FromMilliseconds(500); 
_timer.Tick += _timer_tick; 

// Timer's tick method 
void _timer_tick(object sender, EventArgs e) 
{ 
    // Convert duration to an integer percentage based on current position of 
    // playback and update the slider control 
    TimeSpan ts = meMedia1.NaturalDuration.TimeSpan; 
    int percent = int(meMedia1.Position/ts.Seconds * 100); 
    mySliderControl.Value = percent; 
} 

참고 Slider 누구의 최소가 0이고 최대는 100입니다 당신은 0-1000까지 그것을 범프 (그에 따라 수학 변경) 얻을 수 있습니다 미세한 입도. 이것은 또한 슬라이더가 사용자 상호 작용을 다시 플레이어로 푸시하는 것을 허용하지 않지만 그 반대를 얻는 한 가지 방법에 대한 아이디어를 제공합니다. 사용자가 상호 작용을 시작할 때이 _timer이 중지되도록 (_timer.Stop()) 슬라이더에 이벤트 핸들러를 추가하여 미디어 위치를 업데이트하면 슬라이더가 업데이트되지 않고 대신 슬라이더 -> 미디어 위치 업데이트가 시작됩니다. 그런 다음 사용자가 슬라이더를 놓을 때 _timer을 다시 켜십시오 (_timer.Start()).