@@ -13,6 +13,7 @@
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.IO;
using System.ComponentModel;

namespace Free_Sharp_Player {
public class DynamicBufferBar : Control {
@@ -25,42 +26,192 @@ public class DynamicBufferBar : Control {
/// The total amount of music (in seconds) that can be
/// loaded into memory
/// </summary>
public double MaxBufferSize { get; set; }
public double MaxBufferSize {
get { return (double) GetValue(MaxBufferSizeProperty); }
set { SetValue(MaxBufferSizeProperty, value); }
}
/// <summary>
/// The total amount of music (in seconds) currentlly in memory
/// </summary>
public double TotalBufferSize {
get { return (double)GetValue(TotalBufferSizeProperty); }
set { SetValue(TotalBufferSizeProperty, value); }
}
/// <summary>
// Current stream title
/// </summary>
public String StreamTitle {
get { return (String)GetValue(StreamTitleSizeProperty); }
set { SetValue(StreamTitleSizeProperty, value); }
}
/// <summary>
/// The total amount of music (in seconds) currentlly in memory
/// </summary>
public double TotalBufferSize { get; set; }
public double SongMaxLength {
get { return (double)GetValue(SongMaxLengthProperty); }
set { SetValue(SongMaxLengthProperty, value); }
}
/// <summary>
// Current stream title
/// </summary>
public double SongLength {
get { return (double)GetValue(SongLengthProperty); }
set { SetValue(SongLengthProperty, value);}
}
/// <summary>
/// The total amount of music (in seconds) that's already been
/// played
/// </summary>
public double PlayedBufferSize { get; set; }
public double PlayedBufferSize {
get { return (double)GetValue(PlayedBufferSizeProperty); }
set {
SetValue(PlayedBufferSizeProperty, value);

if (theCanvas == null) return;
double hpos = theCanvas.ActualWidth - (((PlayedBufferSize / MaxBufferSize) * theCanvas.ActualWidth) + 5);
HandlePosition = hpos;
}
}

public double HandlePosition {
get { return (double)GetValue(HandlePositionProperty); }
private set { SetValue(HandlePositionProperty, value); }
}

public static readonly DependencyProperty StreamTitleSizeProperty = DependencyProperty.Register("StreamTitle", typeof(String), typeof(DynamicBufferBar), null);
public static readonly DependencyProperty MaxBufferSizeProperty = DependencyProperty.Register("MaxBufferSize", typeof(double), typeof(DynamicBufferBar), null);
public static readonly DependencyProperty TotalBufferSizeProperty = DependencyProperty.Register("TotalBufferSize", typeof(double), typeof(DynamicBufferBar), null);
public static readonly DependencyProperty PlayedBufferSizeProperty = DependencyProperty.Register("PlayedBufferSize", typeof(double), typeof(DynamicBufferBar), null);
public static readonly DependencyProperty TotalBufferSizeProperty = DependencyProperty.Register("TotalBufferSize", typeof(double), typeof(DynamicBufferBar), new PropertyMetadata(Buff));
public static readonly DependencyProperty PlayedBufferSizeProperty = DependencyProperty.Register("PlayedBufferSize", typeof(double), typeof(DynamicBufferBar), null);
public static readonly DependencyProperty HandlePositionProperty = DependencyProperty.Register("HandlePosition", typeof(double), typeof(DynamicBufferBar), null);
public static readonly DependencyProperty SongMaxLengthProperty = DependencyProperty.Register("SongMaxLength", typeof(double), typeof(DynamicBufferBar), new PropertyMetadata(SongLenChanged));
public static readonly DependencyProperty SongLengthProperty = DependencyProperty.Register("SongLength", typeof(double), typeof(DynamicBufferBar), new PropertyMetadata(SongLenChanged));
#endregion


private static void SongLenChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e) {
DynamicBufferBar h = sender as DynamicBufferBar;
if (h != null) {
h.RedoToolTip();
}
}

private static void Buff(DependencyObject sender, DependencyPropertyChangedEventArgs e) {
DynamicBufferBar h = sender as DynamicBufferBar;
if (h != null) {
Util.Print("====CHANGED====");
}
}

public delegate void SeekDone(double secDiffrence);
public event SeekDone OnSeekDone;

private ProgressBar totalBuffer;
private ProgressBar playedBuffer;
private Canvas theCanvas;
private Button bufferHandle;

private double oldtime = 0;
private bool isHeld = false;
private BitmapImage songChangeImage;
private BitmapImage disconnectImage;
private List<Image> markers = new List<Image>();

public DynamicBufferBar() : base() {
MaxBufferSize = 100;
TotalBufferSize = 50;
protected override void OnInitialized(EventArgs e) {
base.OnInitialized(e);

songChangeImage = new BitmapImage();
songChangeImage.BeginInit();
songChangeImage.UriSource = new Uri(System.IO.Path.Combine(Directory.GetCurrentDirectory(), @"Resources\songchange.png"));
songChangeImage.EndInit();

disconnectImage = new BitmapImage();
disconnectImage.BeginInit();
disconnectImage.UriSource = new Uri(System.IO.Path.Combine(Directory.GetCurrentDirectory(), @"Resources\disconnect.png"));
disconnectImage.EndInit();
}

public override void OnApplyTemplate() {
base.OnApplyTemplate();
/*var PART_Track = GetTemplateChild("PART_Track") as Image;
totalBuffer = GetTemplateChild("BufferedProgress") as ProgressBar;
playedBuffer = GetTemplateChild("PlayedProgress") as ProgressBar;
bufferHandle = GetTemplateChild("BufferHandle") as Button;
theCanvas = GetTemplateChild("Surface") as Canvas;

bufferHandle.PreviewMouseDown += bufferHandle_MouseDown;
bufferHandle.PreviewMouseUp += bufferHandle_MouseUp;
bufferHandle.PreviewMouseMove += bufferHandle_MouseMove;

theCanvas.UpdateLayout();
}


public void RedoToolTip() {
if (SongLength < 0)
ToolTip = "--:-- / --:--";
else
ToolTip = String.Format("{0:D}:{1:D2} / {2:D}:{3:D2}", (int)SongLength/60, (int) SongLength%60, (int)SongMaxLength/60, (int)SongMaxLength%60);
}

BitmapImage logo = new BitmapImage();
logo.BeginInit();
logo.UriSource = new Uri(System.IO.Path.Combine(Directory.GetCurrentDirectory(), "Resources\\stripes.png"));
logo.EndInit();
void bufferHandle_MouseUp(object sender, MouseButtonEventArgs e) {
isHeld = false;

PART_Track.Source = logo;*/
if (OnSeekDone != null)
OnSeekDone(oldtime - PlayedBufferSize);
}

void bufferHandle_MouseMove(object sender, MouseEventArgs e) {
if (!isHeld) return;

var pos = e.MouseDevice.GetPosition(theCanvas);
PlayedBufferSize = Math.Min((pos.X / theCanvas.ActualWidth) * MaxBufferSize, TotalBufferSize);
PlayedBufferSize = Math.Max(PlayedBufferSize, 0);

Util.PrintLine(PlayedBufferSize);

}

void bufferHandle_MouseDown(object sender, MouseButtonEventArgs e) {
isHeld = true;
oldtime = PlayedBufferSize;

//TODO: fire PauseEvent
}

protected override void OnRenderSizeChanged(SizeChangedInfo sizeInfo) {
base.OnRenderSizeChanged(sizeInfo);

PlayedBufferSize++;
PlayedBufferSize--;
}

public void Update(List<EventTuple> events) {
int i = 0;
foreach (EventTuple e in events) {
if (e.Event == EventType.None) continue;

Image image;
if (i < markers.Count)
image = markers[i];
else {
image = new Image();
image.IsHitTestVisible = false;
markers.Add(image);
theCanvas.Children.Add(image);
}
i++;

BitmapImage thePic;
if (e.Event == EventType.Disconnect)
thePic = disconnectImage;
else
thePic = songChangeImage;

image.Source = thePic;
image.SetValue(Canvas.TopProperty, theCanvas.ActualHeight / 2 - thePic.Height / 2);
double pos = theCanvas.ActualWidth - ((e.EventQueuePosition / TotalBufferSize) * theCanvas.ActualWidth);
image.SetValue(Canvas.RightProperty, pos);
}

}


}
@@ -29,6 +29,19 @@ public class MarqueeTextBlock : Label {
private DoubleAnimation text1Anim;
private DoubleAnimation text2Anim;

public double TextPosVertical {
get { return (double)GetValue(TextPosVerticalProperty); }
private set { SetValue(TextPosVerticalProperty, value); }
}
public static readonly DependencyProperty TextPosVerticalProperty = DependencyProperty.Register("TextPosVertical", typeof(double), typeof(MarqueeTextBlock), null);

public double TextPosHorizontal {
get { return (double)GetValue(TextPosHorizontalProperty); }
private set { SetValue(TextPosHorizontalProperty, value); }
}
public static readonly DependencyProperty TextPosHorizontalProperty = DependencyProperty.Register("TextPosHorizontal", typeof(double), typeof(MarqueeTextBlock), null);


static MarqueeTextBlock() {
DefaultStyleKeyProperty.OverrideMetadata(typeof(MarqueeTextBlock), new FrameworkPropertyMetadata(typeof(MarqueeTextBlock)));
}
@@ -48,9 +61,37 @@ public class MarqueeTextBlock : Label {
DoMarqueeLogic();
}


//TODO: handle stretch vertical allingment and all horizontal ones.
protected override void OnRenderSizeChanged(SizeChangedInfo sizeInfo) {
base.OnRenderSizeChanged(sizeInfo);

switch (VerticalContentAlignment) {
case System.Windows.VerticalAlignment.Center:
TextPosVertical = (theCanvas.ActualHeight / 2) - (textBlock1.ActualHeight / 2);
break;
case System.Windows.VerticalAlignment.Bottom:
TextPosVertical = theCanvas.ActualHeight - (textBlock1.ActualHeight / 2);
break;
default:
TextPosVertical = 0;
break;
}

/*switch (HorizontalContentAlignment) {
case System.Windows.HorizontalAlignment.Center:
TextPosHorizontal = (theCanvas.ActualWidth / 2) - (textBlock1.ActualWidth / 2);
break;
case System.Windows.HorizontalAlignment.Right:
TextPosHorizontal = textBlock1.ActualWidth / 2;
break;
default:
TextPosHorizontal = 0;
break;
}*/



DoMarqueeLogic();
}

@@ -61,8 +102,14 @@ public class MarqueeTextBlock : Label {
if (theCanvas != null && textBlock1 != null && textBlock1.ActualWidth >= theCanvas.ActualWidth) {
textBlock2.Visibility = Visibility.Visible;

text1Anim = new DoubleAnimation(0, (textBlock1.ActualWidth + theCanvas.ActualWidth / 2), new Duration(new TimeSpan(0, 0, 10)));
text2Anim = new DoubleAnimation(-(textBlock1.ActualWidth + theCanvas.ActualWidth / 2), 0, new Duration(new TimeSpan(0, 0, 10)));
/*if (HorizontalContentAlignment == System.Windows.HorizontalAlignment.Right) {
text1Anim = new DoubleAnimation((textBlock1.ActualWidth + theCanvas.ActualWidth / 2), 0, new Duration(new TimeSpan(0, 0, 10)));
text2Anim = new DoubleAnimation(0, -(textBlock1.ActualWidth + theCanvas.ActualWidth / 2), new Duration(new TimeSpan(0, 0, 10)));
} else {*/
text1Anim = new DoubleAnimation(0, (textBlock1.ActualWidth + theCanvas.ActualWidth / 2), new Duration(new TimeSpan(0, 0, 10)));
text2Anim = new DoubleAnimation(-(textBlock1.ActualWidth + theCanvas.ActualWidth / 2), 0, new Duration(new TimeSpan(0, 0, 10)));
//}

text1Anim.RepeatBehavior = RepeatBehavior.Forever;
text2Anim.RepeatBehavior = RepeatBehavior.Forever;

@@ -109,10 +109,14 @@
<Button Name="btn_PlayPause" ToolTip="Play/Pause the stream" Content="â–¶" VerticalContentAlignment="Center" BorderThickness="0"/>
</Grid>
<Grid Name="Progress" Grid.Column="1">
<mc:DynamicBufferBar x:Name="MyBuffer" MaxBufferSize="{Binding MaxBufferSize, Mode=OneWay}" TotalBufferSize="{Binding TotalBufferSize, Mode=OneWay}" PlayedBufferSize="{Binding PlayedBufferSize, Mode=OneWay}"
SongMaxLength="{Binding SongMaxLength, Mode=OneWay}" SongLength="{Binding SongLength, Mode=OneWay}" StreamTitle="{Binding TheTitle, Mode=OneWay}"/>
<!--
<ProgressBar Name="bar_Buffer" Foreground="Gray" Maximum="100" Value="{Binding BufferLen}" BorderThickness="0" />
<ProgressBar Name="bar_BufferWindow" Foreground="#22cccc" Background="Transparent" Maximum="100" Value="{Binding PosInBuffer}" BorderThickness="0"/>
<mc:MarqueeTextBlock x:Name="mrq_trackName" Content="{Binding StreamTitle}" FontSize="14" VerticalContentAlignment="Center" VerticalAlignment="Center" Height="30" Margin="4,3,4,0"/>
<ProgressBar Name="bar_SongTime" Foreground="{Binding SongTimeColor}" Maximum="100" Value="{Binding SongProgress}" BorderThickness="0" Margin="0,28,0,0" ToolTip="{Binding SongProgressText}"/>
-->
</Grid>
<Grid Name="OpenVolume" ToolTip="Volume" Grid.Column="2">
<Button Name="btn_Volume" Content="Vol" BorderThickness="0"/>
@@ -164,5 +168,10 @@
</ListView.ItemTemplate>
</ListView>
</Popup>
<Border Name="Connecting" Background="#ccaaaaaa" BorderBrush="Transparent">
<Label Content="Connecting To Stream" VerticalAlignment="Center" VerticalContentAlignment="Center" HorizontalAlignment="Center" HorizontalContentAlignment="Center"
FontSize="18" Padding="0"/>
</Border>

</Grid>
</Window>
@@ -48,15 +48,13 @@ public partial class MainWindow : Window {
[DllImport("kernel32")]
static extern bool AllocConsole();

public enum StreamQuality {Low, Normal, High};
public bool IsPlaying { get; private set; }

private Timer doubleClickCheck = new Timer(350);
private bool isDoubleClicking = false;

//Timer Updater = new Timer(1000);

private StreamManager streamManager;

private MainModel mainModel;
private VolumeModel volumeModel;
@@ -82,18 +80,33 @@ public enum StreamQuality {Low, Normal, High};
btn_PlayPause.IsEnabled = false;
//TODO: UI alert of loading.
new Thread(() => {
ConnectToStream(StreamQuality.Normal);

streamManager.mainUpdateTimer.Elapsed += mainModel.Tick;
streamManager.mainUpdateTimer.Elapsed += volumeModel.Tick;
streamManager.mainUpdateTimer.Elapsed += extraModel.Tick;
streamManager.mainUpdateTimer.Elapsed += playlistModel.Tick;
streamManager.mainUpdateTimer.Elapsed += MainTick;

streamManager.ManualUpdate();
mainModel.ConnectThread();

mainModel.streamManager.NewCurrentTrack += (Track track) => {
lock (trackLock) {
mainModel.UpdateSong(track);
playlistModel.UpdateSong(track);
}
};

mainModel.streamManager.OnRadioUpdate += (getRadioInfo info, List<getLastPlayed> played, List<Track> queued) => {
lock (radioLock) {
mainModel.UpdateInfo(info);
playlistModel.UpdateLists(played, queued);
extraModel.UpdateInfo(info);
playlistModel.UpdateInfo(info);

}
};

mainModel.streamManager.mainUpdateTimer.Elapsed += volumeModel.Tick;
mainModel.streamManager.mainUpdateTimer.Elapsed += extraModel.Tick;
mainModel.streamManager.mainUpdateTimer.Elapsed += playlistModel.Tick;
mainModel.streamManager.mainUpdateTimer.Elapsed += MainTick;

Dispatcher.Invoke(new Action(() => {
btn_PlayPause.IsEnabled = true;
Connecting.Visibility = System.Windows.Visibility.Collapsed;
}));
}).Start();
}
@@ -105,62 +118,14 @@ public enum StreamQuality {Low, Normal, High};
}


public void Play() { IsPlaying = true; streamManager.Play(); }
public void Stop() { IsPlaying = false; streamManager.Stop(); }
public void Play() { IsPlaying = true; mainModel.streamManager.Play(); }
public void Stop() { IsPlaying = false; mainModel.streamManager.Stop(); }

public void SetVolume(double Volume) {
if (Volume < 0 || Volume > 100) throw new ArgumentOutOfRangeException("Volume", Volume, "Volume must be between 0 and 100");

if (streamManager != null)
streamManager.Volume = (float)Volume / 100;
}

private void ConnectToStream(StreamQuality Quality) {
String address = "";
bool Connected = false;

while (!Connected) {

getRadioInfo temp = getRadioInfo.doPost();

using (WebClient wb = new WebClient()) {
NameValueCollection data = new NameValueCollection();
String tempAddr = temp.servers.medQuality.Split("?".ToCharArray())[0];
data["sid"] = temp.servers.medQuality.Split("=".ToCharArray())[1];//(Quality == StreamQuality.Normal ? "1" : (Quality == StreamQuality.Low ? "3" : "2"));

Byte[] response = wb.UploadValues(tempAddr, "POST", data);

string[] responseData = System.Text.Encoding.UTF8.GetString(response, 0, response.Length).Split("\n".ToCharArray(), StringSplitOptions.None);

//Todo: timeout, check for valid return data, find the adress in more dynamic way.
address = responseData[2].Split("=".ToCharArray())[1];
}


try {
streamManager = new StreamManager(address);

streamManager.NewCurrentTrack += (Track track) => {
lock (trackLock) {
mainModel.UpdateSong(track);
playlistModel.UpdateSong(track);
}
};

streamManager.OnRadioUpdate += (getRadioInfo info, List<getLastPlayed> played, List<Track> queued) => {
lock (radioLock) {
mainModel.UpdateInfo(info);
playlistModel.UpdateLists(played, queued);
extraModel.UpdateInfo(info);
playlistModel.UpdateInfo(info);

}
};

Connected = true;
} catch (Exception) { }
}

if (mainModel.streamManager != null)
mainModel.streamManager.Volume = (float)Volume / 100;
}


@@ -174,7 +139,7 @@ public enum StreamQuality {Low, Normal, High};
}

private void Window_Closed(object sender, EventArgs e) {
streamManager.Stop();
mainModel.streamManager.Stop();
Application.Current.Shutdown();
}

@@ -18,7 +18,7 @@
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>

<mc:MarqueeTextBlock Grid.Row="1" mc:Content="~~~~Dat Scrolling Text~~~~" Background="Pink" x:Name="MyTextControlTest" />
<mc:MarqueeTextBlock Grid.Row="1" mc:Content="~~~~Dat Scrolling Text~~~~" VerticalContentAlignment="Stretch" Background="Pink" x:Name="MyTextControlTest" />
<mc:DynamicBufferBar Grid.Row="2" x:Name="MyBuffer" />
<TextBlock Grid.Row="3" Text="Some Long Text" Background="Pink" Name="NormalTextControl" />
<ProgressBar Name="prog" Grid.Row="4" Maximum="100" IsEnabled="True"/>
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using System.Timers;
@@ -18,32 +19,31 @@ namespace Free_Sharp_Player.UI {
/// Interaction logic for TestWindow.xaml
/// </summary>
public partial class TestWindow : Window {
[DllImport("kernel32")]
static extern bool AllocConsole();

public TestWindow() {
InitializeComponent();

bool asdf = true;
MyBuffer.MaxBufferSize = 100;
MyBuffer.TotalBufferSize = 0;
AllocConsole();
/*MyBuffer.MaxBufferSize = 100;
MyBuffer.TotalBufferSize = 75;
MyBuffer.PlayedBufferSize = MyBuffer.TotalBufferSize - 15;*/
prog.Value = 0;

Timer lol = new Timer();
lol.Interval = 25;
lol.AutoReset = true;
lol.Interval = 1000;
lol.AutoReset = false;
lol.Enabled = true;
lol.Elapsed += (o, e) => {
Dispatcher.Invoke(new Action(() => {
MyTextControlTest.Content = "~~~~Dat Scrolling Text~~~~";

if (asdf) {
MyBuffer.TotalBufferSize++;
prog.Value++;
} else {
MyBuffer.TotalBufferSize--;
prog.Value--;
}
List<EventTuple> events = new List<EventTuple>() {
new EventTuple() {Event = EventType.SongChange, EventQueuePosition = 25},
new EventTuple() {Event = EventType.Disconnect, EventQueuePosition = 50}
};

if (prog.Value == 100 || prog.Value == 0)
asdf = !asdf;
//MyBuffer.Update("Some long stream name - artist", 100, 90, 75, 120, 35, events);
}));
};
lol.Start();
@@ -5,6 +5,7 @@
using System.Text;
using System.Threading.Tasks;
using System.Windows.Data;
using System.Windows.Media;

namespace Free_Sharp_Player {
public class SliderToVolumeConverter : IValueConverter {
@@ -42,6 +43,50 @@ public class DurationConverter : IValueConverter {
}
}

public class SongLengthSafetyConverter : IValueConverter {
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) {
double len = (double)value;
if (len < 0)
return 1;
else
return len;
}

public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) {
// Do the conversion from visibility to bool
throw new NotImplementedException();
}
}


public class SongLengthToTimeConverter : IValueConverter {
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) {
double len = (double)value;
if (len < 0)
return "Brodcast is Live";
else
return String.Format("{0:D}:{1:D2}", (int)len/60, (int) len%60);
}

public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) {
// Do the conversion from visibility to bool
throw new NotImplementedException();
}
}

public class SongLengthToColorConverter : IValueConverter {
private static BrushConverter con = new BrushConverter();
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) {
double len = (double)value;
return (len > 0 ? con.ConvertFromString("#2ECC71") : con.ConvertFromString("#D91E18")) as Brush;
}

public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) {
// Do the conversion from visibility to bool
throw new NotImplementedException();
}
}

public class LastPlayedConverter : IValueConverter {
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) {
String date = (String)value;
@@ -1,8 +1,10 @@
using NAudio.Wave;
using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Globalization;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
@@ -15,12 +17,13 @@ namespace Free_Sharp_Player {
public class MainModel : ViewModelNotifier {
private Object theLock = new Object();

public int PosInBuffer { get { return GetProp<int>(); } set { SetProp(value); } }
public int BufferLen { get { return GetProp<int>(); } set { SetProp(value); } }
public int SongLength { get { return GetProp<int>(); } set { SetProp(value); } }
public int SongProgress { get { return GetProp<int>(); } set { SetProp(value); } }
public String SongTimeColor { get { return GetProp<String>(); } set { SetProp(value); } }
public String SongProgressText { get { return GetProp<String>(); } set { SetProp(value); } }

public double MaxBufferSize { get { return GetProp<double>(); } set { SetProp(value); } }
public double TotalBufferSize { get { return GetProp<double>(); } set { SetProp(value); } }
public double PlayedBufferSize { get { return GetProp<double>(); } set { SetProp(value); } }
public double SongMaxLength { get { return GetProp<double>(); } set { SetProp(value); } }
public double SongLength { get { return GetProp<double>(); } set { SetProp(value); } }
public String TheTitle { get { return GetProp<String>(); } set { SetProp(value); } }

private Track currentSong;
private bool isLive;
@@ -32,6 +35,8 @@ public class MainModel : ViewModelNotifier {
MouseButtonEventHandler VolumeOutClick;
MouseButtonEventHandler ExtrasOutClick;

public StreamManager streamManager;


//TODO: add to configs.
private String liveColor = "#22cccc";
@@ -43,16 +48,18 @@ public class MainModel : ViewModelNotifier {
window = win;


window.bar_Buffer.DataContext = this;
window.bar_BufferWindow.DataContext = this;
window.bar_SongTime.DataContext = this;
window.MyBuffer.DataContext = this;

window.btn_PlayPause.Click += btn_PlayPause_Click;
window.btn_Volume.Click += btn_Volume_Click;
window.btn_Extra.Click += btn_Extra_Click;
window.btn_Like.Click += btn_Like_Click;
window.btn_Dislike.Click += btn_Dislike_Click;

window.MyBuffer.OnSeekDone += (sec) => {
if (streamManager != null)
streamManager.Seek(sec);
};

VolumeOutClick = new MouseButtonEventHandler(HandleClickOutsideOfVolume);
ExtrasOutClick = new MouseButtonEventHandler(HandleClickOutsideOfExtras);
@@ -63,10 +70,48 @@ public class MainModel : ViewModelNotifier {
isLive = false;
}

public void ConnectThread() {
ConnectToStream(StreamQuality.Normal);

streamManager.mainUpdateTimer.Elapsed += Tick;

MaxBufferSize = streamManager.MaxBufferSize;

streamManager.ManualUpdate();
}

private void ConnectToStream(StreamQuality Quality) {
String address = "";
bool Connected = false;

while (!Connected) {

getRadioInfo temp = getRadioInfo.doPost();

using (WebClient wb = new WebClient()) {
NameValueCollection data = new NameValueCollection();
String tempAddr = temp.servers.medQuality.Split("?".ToCharArray())[0];
data["sid"] = temp.servers.medQuality.Split("=".ToCharArray())[1];//(Quality == StreamQuality.Normal ? "1" : (Quality == StreamQuality.Low ? "3" : "2"));

Byte[] response = wb.UploadValues(tempAddr, "POST", data);

string[] responseData = System.Text.Encoding.UTF8.GetString(response, 0, response.Length).Split("\n".ToCharArray(), StringSplitOptions.None);

//Todo: timeout, check for valid return data, find the adress in more dynamic way.
address = responseData[2].Split("=".ToCharArray())[1];
}


streamManager = new StreamManager(address);

Connected = true;
}

}

public void UpdateSong(Track song) {
currentSong = song;

TheTitle = song.WholeTitle;
getVoteStatus tempStatus = getVoteStatus.doPost();
//TODO: make this not rely on a post.
currentSong.MyVote = tempStatus.vote != null ? (int)tempStatus.vote : 0;
@@ -108,17 +153,21 @@ public class MainModel : ViewModelNotifier {

public void UpdateInfo(getRadioInfo info) {
isLive = int.Parse(info.autoDJ) == 0;

}

//TODO: make sure to fix this.
public void Tick(Object o, EventArgs e) {
lock (theLock) {
//lock (theLock) {
//window.MyBuffer.Update(streamManager.GetEvents());
TotalBufferSize = streamManager.TotalLength;
PlayedBufferSize = streamManager.PlayedLegnth;

if (isLive || currentSong == null || !window.IsPlaying) {
SongTimeColor = notLiveColor;
SongProgress = 100;
SongLength = -1;
SongMaxLength = 1;
return;
} else
SongTimeColor = liveColor;
}

DateTime lastPlayedDate;
if (currentSong.localLastPlayed != new DateTime(0)) {
@@ -130,9 +179,9 @@ public class MainModel : ViewModelNotifier {

TimeSpan SongDuration = TimeSpan.Parse(currentSong.duration);
TimeSpan duration = DateTime.Now - lastPlayedDate;
SongProgress = (int)((duration.TotalSeconds / SongDuration.TotalSeconds) * 100);
SongProgressText = "Duration: " + duration.TotalSeconds + ", SongDuration: " + (SongDuration.TotalSeconds);
}
SongMaxLength = SongDuration.TotalSeconds;
SongLength = (duration.TotalSeconds / SongDuration.TotalSeconds ) * 100;
//}
}


@@ -40,7 +40,6 @@ class PlaylistModel : ViewModelNotifier {

window.QueueList.DataContext = this;
window.PlayedList.DataContext = this;
window.mrq_trackName.DataContext = this;


Tick(null, null);
Binary file not shown.
Binary file not shown.