Stilllegung des Forums
Das Forum wurde am 05.06.2023 nach über 20 Jahren stillgelegt (weitere Informationen und ein kleiner Rückblick).
Registrierungen, Anmeldungen und Postings sind nicht mehr möglich. Öffentliche Inhalte sind weiterhin zugänglich.
Das Team von spieleprogrammierer.de bedankt sich bei der Community für die vielen schönen Jahre.
Wenn du eine deutschsprachige Spieleentwickler-Community suchst, schau doch mal im Discord und auf ZFX vorbei!
Werbeanzeige
Quellcode |
|
1 |
<Slider DockPanel.Dock="Top" Value="{Binding CurrentTime}" Maximum="{Binding CurrentChannelLength}" /> |
C#-Quelltext |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
public class PlayerViewModel:DependencyObject { //... private AudioPlayer player; public AudioPlayer Player { get { return player; } } public PlayerViewModel() { player = new AudioPlayer(); player.PropertyChanged += player_PropertyChanged; //... } void player_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e) { if (e.PropertyName.Equals("CurrentChannelPosition")) { CurrentTime = player.CurrentChannelPosition; } else if(e.PropertyName.Equals("CurrentChannelLength")) { CurrentChannelLength = player.CurrentChannelLength; } } public static readonly DependencyProperty CurrentTimeProperty = DependencyProperty.Register("CurrentTime", typeof(long), typeof(PlayerViewModel), new PropertyMetadata(setCurrentTime)); private static void setCurrentTime(DependencyObject o, DependencyPropertyChangedEventArgs e) { (o as PlayerViewModel).player.SetChannelPosition((long)e.NewValue); } public long CurrentTime { get { return (long)GetValue(CurrentTimeProperty); } set { SetValue(CurrentTimeProperty, value); } } public static readonly DependencyProperty CurrentChannelLengthProperty = DependencyProperty.Register("CurrentChannelLength", typeof(long), typeof(PlayerViewModel)); public long CurrentChannelLength { get { return (long)GetValue(CurrentChannelLengthProperty); } set { SetValue(CurrentChannelLengthProperty, value); } } //... } |
C#-Quelltext |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
public class AudioPlayer:INotifyPropertyChanged { //.... private DispatcherTimer positionTimer; private long currentChannelPosition; private long currentChannelLength; public long CurrentChannelPosition { get { return currentChannelPosition; } set { currentChannelPosition = value; NotifyPropertyChanged("CurrentChannelPosition"); } } public long CurrentChannelLength { get { return currentChannelLength; } set { currentChannelLength = value; NotifyPropertyChanged("CurrentChannelLength"); } } //... private int currentStreamHandle; public int CurrentStreamHandle { get { return currentStreamHandle; } set { currentStreamHandle = value; } } public AudioPlayer() { positionTimer = new DispatcherTimer(DispatcherPriority.ApplicationIdle); positionTimer.Interval = TimeSpan.FromMilliseconds(100); positionTimer.Tick += positionTimerTick; positionTimer.IsEnabled = true; //... } //... public void SetChannelPosition(long position) { CurrentChannelPosition = Math.Max(0, Math.Min(position, CurrentChannelLength)); Bass.BASS_ChannelSetPosition(CurrentStreamHandle, Math.Max(0, Math.Min(position, CurrentChannelLength))); } public event PropertyChangedEventHandler PropertyChanged; private void NotifyPropertyChanged(String info) { if (PropertyChanged != null) { PropertyChanged(this, new PropertyChangedEventArgs(info)); } } } |
Es ist ja keine Schande etwas falsch zu machen, als Programmierer tu ich das täglich, [...].
Community-Fossil
Beruf: Teamleiter Mobile Applikationen & Senior Software Engineer
C#-Quelltext |
|
1 2 3 4 5 6 7 8 9 10 |
public long CurrentPosition { get { return CurrentSong.Position; } set { Bass....setPosition(value); NotifyPropertyChanged("CurrentPosition"); } } public ForceVisualUpdate() { NotifyPropertyChanged("CurrentPosition"); } |
@Chromanoid:
Geändert hat sich der Wert immer. Nur ein mal ging es aus der Audio Engine im Model und einmal aus der View heraus.
Quellcode |
|
1 2 |
public long CurrentChannelPosition { get { return currentChannelPosition; } set { long old = currentChannelPosition; currentChannelPosition = value; if(old!=value) NotifyPropertyChanged("CurrentChannelPosition"); } } public long CurrentChannelLength { get { return currentChannelLength; } set { long old = currentChannelLength; currentChannelLength = value; if(old!=value) NotifyPropertyChanged("CurrentChannelLength"); } } |
Werbeanzeige