Example #1
0
    private void InitializeUI()
    {
        InitializeButtons();
        label   = transform.Find("Label").GetComponent <TextMesh>();
        caption = transform.Find("TextField").GetComponent <Caption>();
        caption.Init();

        // initialize audio progress bar
        Transform audioProgressBarTransform = transform.Find("Audio Progress Bar");

        if (audioProgressBarTransform != null)
        {
            audioProgressBar = audioProgressBarTransform.GetComponent <AudioProgressBar>();
            if (audioProgressBar != null && container != null)
            {
                audioProgressBar.Source = container.AnnotationAudioSource;
            }
        }
    }
		StackPanel CreateAudioStackPanel(string audioId)
		{
			bool isAudioReseived = false;
			string audioUrl = string.Empty;
			string audioArtist = string.Empty;
			string audioTitle = string.Empty;
			SolidColorBrush color = new SolidColorBrush((Color)Application.Current.Resources["PhoneAccentColor"]);
			if (User)
				color.Opacity = 0.7;
			StackPanel definitiveStackPanel = new StackPanel()
			{
				Orientation = System.Windows.Controls.Orientation.Horizontal,
				Background = Application.Current.Resources["PhoneAccentBrush"] as Brush,
			};

			AudioProgressBar progressBar = new AudioProgressBar();
			BackgroundAudioPlayer.Instance.PlayStateChanged += new EventHandler(Instance_PlayStateChanged);
			MessagesPage.AudioAttachmentResponseReceived += (audioInfo) =>
			{
				if (audioInfo.aid == audioId)
				{
					audioUrl = audioInfo.url;
					audioArtist = audioInfo.artist;
					audioTitle = audioInfo.title;
					isAudioReseived = true;
				}
			};

			DispatcherTimer timer = new DispatcherTimer();
			timer.Interval = TimeSpan.FromSeconds(1);

			//timer.Tick += (o, e) => { progressBar.playingState.Margin = new Thickness(audio.NaturalDuration.TimeSpan/audio.Position, 0, 0, 0); };
			//	progressBar.place.Width = i + 15;
			StackPanel playStackPanel = new StackPanel()
			{
				Margin = new Thickness(10, 10, 10, 0)
			};

			Image circle = new Image();
			circle.Source = new BitmapImage(new Uri("/Icons/appbar.basecircle.rest.png", UriKind.Relative));

			Image play = new Image();
			play.Source = new BitmapImage(new Uri("/Icons/appbar.transport.play.rest.png", UriKind.Relative));
			play.Margin = new Thickness(0, -50, 0, 0);
			play.Tag = "play";

			Image pause = new Image();
			pause.Source = new BitmapImage(new Uri("/Icons/appbar.transport.pause.rest.png", UriKind.Relative));
			pause.Margin = new Thickness(0, -50, 0, 0);
			pause.Tag = "pause";

			playStackPanel.Tap += (o, e) =>
			{
				//if ((playStackPanel.Children[1] as Image).Tag == "play")
				if (isAudioReseived)
				{
					if ((playStackPanel.Children[1] as Image).Tag == "play")
					{
						//BackgroundAudioPlayer.Instance.Track.Source = new Uri(.url);
						if (BackgroundAudioPlayer.Instance.Track.Tag == audioId)
						{
							if (db.AudioPlaylist != null)
							{
								if (db.AudioPlaylist.Count() > 0)
								{
									db.AudioPlaylist.DeleteAllOnSubmit((from aud in db.AudioPlaylist select aud));
									db.SubmitChanges();
								}
							}
							db.AudioPlaylist.InsertOnSubmit(new AudioPlaylistTable() { Aid = audioId, AudioUrl = audioUrl, AudioArtist = audioArtist, AudioTitle = audioTitle });
							db.SubmitChanges();
							BackgroundAudioPlayer.Instance.Play();
							timer.Start();
							playStackPanel.Children.Remove(play);
							playStackPanel.Children.Add(pause);
						}
						else
						{

							BackgroundAudioPlayer.Instance.Pause();
							timer.Stop();
							playStackPanel.Children.Remove(pause);
							playStackPanel.Children.Add(play);
						}
					}
				}
			};

			playStackPanel.Children.Add(circle);
			playStackPanel.Children.Add(play);

			StackPanel audioCOntentStackPanel = new StackPanel()
			{
				Orientation = System.Windows.Controls.Orientation.Vertical,
				Margin = new Thickness(10, 5, 10, 10)
			};
			TextBlock song = new TextBlock() { FontSize = 35 };
			song.Text = "bsad jkashkjhasf";
			TextBlock author = new TextBlock() { FontSize = 20 };
			author.Text = "asdfsdg sgdhfd";


			progressBar.HorizontalAlignment = HorizontalAlignment.Left;

			audioCOntentStackPanel.Children.Add(song);
			audioCOntentStackPanel.Children.Add(author);
			audioCOntentStackPanel.Children.Add(progressBar);

			definitiveStackPanel.Children.Add(playStackPanel);
			definitiveStackPanel.Children.Add(audioCOntentStackPanel);

			return definitiveStackPanel;
		}