private void SliderPostionValueChanged(object sender, ValueChangedEventArgs e) { if (sliderPosition.Value != player.Duration) { player.Seek(sliderPosition.Value); } }
private void SliderPositionValueChanged(object sender, ValueChangedEventArgs e) { if (Math.Abs(Slider.Value - _player.Duration) > 0.00001) { _player.Seek(Slider.Value); } }
public void SliderPostionValueChanged(object sender, ValueChangedEventArgs e) { if (MainSlider.Value != player.Duration) { player.Seek(MainSlider.Value); } }
public void PlayerSlider_ValueChanged(object sender, Xamarin.Forms.ValueChangedEventArgs e) { if (sliderPositionAudio.Value != player.Duration) { player.Seek(sliderPositionAudio.Value); } }
private void UserDraggedSlider(object sender, EventArgs e) { //when the slider is dragged change the playback if (StoryPageSlider.Value < player.Duration) { player.Seek(StoryPageSlider.Value); } }
private void SliderPostionValueChanged(object sender, ValueChangedEventArgs e) { if (sliderPosition.Value != player.Duration) { player.Seek(sliderPosition.Value); } lblPosition.Text = $"Postion: {(int)sliderPosition.Value} / {(int)player.Duration}"; }
public void SetPosition(double dValue) { player.Seek(dValue); }
public void Forward(double secs) { var toSeek = _impl.CurrentPosition + secs; _impl.Seek(toSeek); }
public ThinkAndDoPopup(ThinkAndDo thinkAndDo) { InitializeComponent(); ThinkAndDoTitle.Text = thinkAndDo.ThinkAndDoName; ThinkAndDoText.Text = thinkAndDo.Text; ImageButton button = new ImageButton() { Source = "pause.png", BackgroundColor = Color.Transparent }; ImageButton button2 = new ImageButton() { Source = "play.png", IsVisible = false, BackgroundColor = Color.Transparent }; Label displayLabel = new Label { Text = "0:00", TextColor = Color.White }; Slider slider = new Slider { Maximum = thinkAndDo.Length.Seconds + (thinkAndDo.Length.Minutes * 60), Minimum = 0, Value = 0, HorizontalOptions = LayoutOptions.FillAndExpand, HeightRequest = 50 // Controls size of area that can grab the slider }; ImageButton close = new ImageButton() { Source = "CloseButton", BackgroundColor = Color.Transparent }; close.Clicked += (sender, args) => { player.Stop(); CloseAllPopup(); }; player = Plugin.SimpleAudioPlayer.CrossSimpleAudioPlayer.Current; player.Load(thinkAndDo.ThinkAndDoAudioClip); bool audioFromTimer = false; bool playAudio = true; player.Play(); button.Clicked += (sender, args) => { player.Pause(); playAudio = false; button.IsVisible = false; button2.IsVisible = true; }; button2.Clicked += (sender, args) => { player.Play(); playAudio = true; button.IsVisible = true; button2.IsVisible = false; }; Device.StartTimer(new TimeSpan(0, 0, 1), () => { if (playAudio) { audioFromTimer = true; slider.Value += 1; } return(true); }); slider.ValueChanged += (sender, args) => { int minutes = (int)args.NewValue / 60; int seconds = (int)args.NewValue - (minutes * 60); Console.WriteLine(args.NewValue); Console.WriteLine(player.CurrentPosition); Console.WriteLine(args.NewValue); if (!audioFromTimer) { player.Seek(args.NewValue); } String second = seconds.ToString(); if (seconds < 10) { second = '0' + seconds.ToString(); } displayLabel.Text = String.Format("{0}:{1}", minutes, second); var timeStamp = new TimeSpan(0, minutes, seconds); audioFromTimer = false; if (timeStamp.Equals(thinkAndDo.Length)) { thinkAndDo.Completed = true; } }; StackLayout audio = new StackLayout { Orientation = StackOrientation.Horizontal, Children = { button, button2, displayLabel, close } }; TopStack.Children.Add(slider); TopStack.Children.Add(audio); }
public HomeViewModel() { GenreList = new ObservableRangeCollection <Genre>(); PredictedLabel = "Genre"; var entries = new[] { new ChartEntry(212) { Label = "What will it be?", ValueLabel = "212", Color = SKColor.Parse("#2c3e50") } }; CurrentChart = new DonutChart() { Entries = entries, IsAnimated = true, AnimationDuration = TimeSpan.FromSeconds(5) }; AggChart = new DonutChart() { Entries = entries, IsAnimated = true, AnimationDuration = TimeSpan.FromSeconds(5) }; recorder = new AudioRecorderService { StopRecordingOnSilence = false, //will stop recording after 2 seconds (default) StopRecordingAfterTimeout = true, //stop recording after a max timeout (defined below) TotalAudioTimeout = TimeSpan.FromSeconds(30) //audio will stop recording after 15 seconds }; //player = new AudioPlayer(); playCommand = new Command(() => { var files = Assembly.GetExecutingAssembly().GetManifestResourceNames(); Console.WriteLine($"AUDXAM ALL FILES: {files.Length} {files.ToList()} { files[0]}"); if (recorder.IsRecording != true && player.IsPlaying == false) { //player.Load(GetStreamFromFile()); player.Play(); var startTimeSpan = TimeSpan.Zero; var periodTimeSpan = TimeSpan.FromMilliseconds(60); float[] op2 = new float[10]; Array.Clear(op2, 0, op2.Length); timer = new System.Threading.Timer((e) => { if (player.IsPlaying) { //Console.WriteLine($"{tag} CURRENT PREDICTION: {op.Score[9]} curPos:{Convert.ToInt32(player.CurrentPosition)} M AT ZERO {featureTimeList[0].Mfcc0} AT FIVE {featureTimeList[5].Mfcc0} FINAL -> {ConsumeModel.Predict(featureTimeList[Convert.ToInt32(player.CurrentPosition)]).Score[5]}"); op = featureTimeList[Convert.ToInt32(player.CurrentPosition)]; for (int i = 0; i < 10; i++) { op2[i] += op[i]; } float max_sf = 0; int max_ind = 0; string[] labels = "Blues, Classical, Country, Disco, HipHop, Jazz, Metal, Pop, Reggae Rock".Split(','); for (int i = 0; i < 10; i++) { if (op2[i] > max_sf) { max_sf = op2[i]; max_ind = i; } } PredictedLabel = $"{labels[max_ind]}!"; //Pass to ML.net var entries_agg = new[] { new ChartEntry(op2[0]) { Label = "Blues", ValueLabel = $"{op2[0]}", Color = SKColor.Parse("#2c3e50") }, new ChartEntry(op2[1]) { Label = "Classical", ValueLabel = $"{op2[1]}", Color = SKColor.Parse("#77d065") }, new ChartEntry(op2[2]) { Label = "Country", ValueLabel = $"{op2[2]}", Color = SKColor.Parse("#b455b6") }, new ChartEntry(op2[3]) { Label = "Disco", ValueLabel = $"{op2[3]}", Color = SKColor.Parse("#245e50") }, new ChartEntry(op2[4]) { Label = "Hiphop", ValueLabel = $"{op2[4]}", Color = SKColor.Parse("#3498db") }, new ChartEntry(op2[5]) { Label = "Jazz", ValueLabel = $"{op2[5]}", Color = SKColor.Parse("#263e50") }, new ChartEntry(op2[6]) { Label = "Metal", ValueLabel = $"{op2[6]}", Color = SKColor.Parse("#123456") }, new ChartEntry(op2[7]) { Label = "Pop", ValueLabel = $"{op2[7]}", Color = SKColor.Parse("#654321") }, new ChartEntry(op2[8]) { Label = "Reggae", ValueLabel = $"{op2[8]}", Color = SKColor.Parse("#526784") }, new ChartEntry(op2[9]) { Label = "Rock", ValueLabel = $"{op2[9]}", Color = SKColor.Parse("#404040") } }; var entries_current = new[] { new ChartEntry(op[0]) { Label = "Blues", ValueLabel = $"{op[0]}", Color = SKColor.Parse("#2c3e50") }, new ChartEntry(op[1]) { Label = "Classical", ValueLabel = $"{op[1]}", Color = SKColor.Parse("#77d065") }, new ChartEntry(op[2]) { Label = "Country", ValueLabel = $"{op[2]}", Color = SKColor.Parse("#b455b6") }, new ChartEntry(op[3]) { Label = "Disco", ValueLabel = $"{op[3]}", Color = SKColor.Parse("#245e50") }, new ChartEntry(op[4]) { Label = "Hiphop", ValueLabel = $"{op[4]}", Color = SKColor.Parse("#3498db") }, new ChartEntry(op[5]) { Label = "Jazz", ValueLabel = $"{op[5]}", Color = SKColor.Parse("#263e50") }, new ChartEntry(op[6]) { Label = "Metal", ValueLabel = $"{op[6]}", Color = SKColor.Parse("#123456") }, new ChartEntry(op[7]) { Label = "Pop", ValueLabel = $"{op[7]}", Color = SKColor.Parse("#654321") }, new ChartEntry(op[8]) { Label = "Reggae", ValueLabel = $"{op[8]}", Color = SKColor.Parse("#526784") }, new ChartEntry(op[9]) { Label = "Rock", ValueLabel = $"{op[9]}", Color = SKColor.Parse("#404040") } }; //Update and draw graph AggChart = new DonutChart() { Entries = entries_agg, IsAnimated = false, AnimationDuration = TimeSpan.FromMilliseconds(0) }; //CurrentChart = new DonutChart() { Entries = entries_current, IsAnimated = false, AnimationDuration = TimeSpan.FromMilliseconds(0) }; //Console.WriteLine($"{tag} Updated chart! C {op.Score[9]} A ->{op2[9]}"); //Graph 1 -> Current prediciton //Graph 2 -> Aggregate of predictions so far } else { player.Seek(0.0); timer.Dispose(); } }, null, startTimeSpan, periodTimeSpan); } }); recordCommand = new Command(async() => { if (RecordStatus != "record") { PredictedLabel = "Processing audio..."; await recorder.StopRecording().ConfigureAwait(true); if (_filePath != null) { //await extractFeatures(); var stream = new FileStream(_filePath, FileMode.Open); AudioFunctions.WriteWavHeader(stream, 1, 48000, 16, (int)stream.Length - 44); stream.Close(); player.Load(GetStreamFromFile()); //player.Play(); duration = Convert.ToInt32(player.Duration); Console.WriteLine($"{tag} DUR: {duration}"); // player.Dispose(); extractFeatures(); //await predict } RecordStatus = "record"; } else { PredictedLabel = "Recording..."; IsBusy = true; RecordStatus = "stop"; var recordTask = await recorder.StartRecording().ConfigureAwait(true); _filePath = await recordTask.ConfigureAwait(true); //player.Play(_filePath } }); }
public StoryPage(Story story) { InitializeComponent(); settingsPage = new Settings(); ImageButton button = new ImageButton() { Source = "pause.png", HeightRequest = 40, BorderColor = Color.Transparent, BackgroundColor = Color.Transparent, Margin = 20 }; ImageButton button2 = new ImageButton() { Source = "play.png", IsVisible = false, HeightRequest = 40, BorderColor = Color.Transparent, BackgroundColor = Color.Transparent, Margin = 20 }; ImageButton Expand = new ImageButton() { Source = "expand.png", HorizontalOptions = LayoutOptions.EndAndExpand, HeightRequest = 40, BorderColor = Color.Transparent, BackgroundColor = Color.Transparent, Margin = 20 }; ImageButton QuizButton = new ImageButton() { Source = "Quizzes.png", BackgroundColor = Color.Green, IsVisible = false }; Label displayLabel = new Label { Text = "0:00", FontFamily = Device.RuntimePlatform == Device.Android ? "Comic.ttf#Comic" : "Comic", Margin = 20 }; Slider slider = new Slider { Maximum = story.Duration.Seconds + (story.Duration.Minutes * 60), Minimum = 0, Value = 0, HorizontalOptions = LayoutOptions.FillAndExpand, HeightRequest = 50 // Controls size of area that can grab the slider }; Image storyImage = new Image() { Source = story.PictureCues[new TimeSpan(0, 0, 0)], HeightRequest = 150 }; var tapGestureRecognizer = new TapGestureRecognizer(); tapGestureRecognizer.Tapped += (s, e) => { if (oldContent != null) { Content = oldContent; storyImage.HeightRequest = 150; fullScreen = false; } }; storyImage.GestureRecognizers.Add(tapGestureRecognizer); Expand.Clicked += (sender, args) => { if (!fullScreen) { Content = storyImage; fullScreen = true; } }; player = Plugin.SimpleAudioPlayer.CrossSimpleAudioPlayer.Current; player.Load(story.AudioClip); bool audioFromTimer = false; bool playAudio = true; player.Play(); Device.StartTimer(new TimeSpan(0, 0, 1), () => { if (playAudio) { audioFromTimer = true; slider.Value += 1; } if (slider.Value == story.Duration.Seconds + (story.Duration.Minutes * 60)) { player.Stop(); if (story.QuizNum > 0) { ChangePage(story); } else { GoBack(); } return(false); } return(true); }); button.Clicked += (sender, args) => { player.Pause(); playAudio = false; button.IsVisible = false; button2.IsVisible = true; }; button2.Clicked += (sender, args) => { player.Seek(timeStamp.TotalSeconds); player.Play(); playAudio = true; button.IsVisible = true; button2.IsVisible = false; }; QuizButton.Clicked += (sender, args) => { Navigation.PushAsync(new QuizPage(story.Quizzes[quizNum], story.AudioClip)); QuizButton.IsVisible = false; button.IsVisible = false; button2.IsVisible = true; }; slider.ValueChanged += (sender, args) => { QuizButton.IsVisible = false; int minutes = (int)args.NewValue / 60; int seconds = (int)args.NewValue - (minutes * 60); Console.WriteLine(args.NewValue); Console.WriteLine(player.CurrentPosition); Console.WriteLine(args.NewValue); if (!audioFromTimer) { player.Seek(args.NewValue); } String second = seconds.ToString(); if (seconds < 10) { second = '0' + seconds.ToString(); } displayLabel.Text = String.Format("{0}:{1}", minutes, second); timeStamp = new TimeSpan(0, minutes, seconds); var savedTime = new TimeSpan(0, 0, 0); foreach (TimeSpan key in story.PictureCues.Keys) { if (key.TotalSeconds < args.NewValue) { savedTime = key; } else { break; } } storyImage.Source = story.PictureCues[savedTime]; quizNum = -1; for (int i = 0; i < story.QuizNum; i++) { if (timeStamp.CompareTo(story.Quizzes[i].PlayTime) >= 0) { quizNum++; } } for (int i = 0; i < story.QuizNum; i++) { if (timeStamp.Equals(story.Quizzes[i].PlayTime)) { player.Pause(); QuizButton.IsVisible = true; playAudio = false; button.IsVisible = false; button2.IsVisible = true; Content = oldContent; storyImage.HeightRequest = 150; fullScreen = false; } } audioFromTimer = false; }; StackLayout audio = new StackLayout { Orientation = StackOrientation.Horizontal, Children = { button, button2, displayLabel, QuizButton, Expand } }; TopStack.Children.Add(storyImage); TopStack.Children.Add(slider); TopStack.Children.Add(audio); oldContent = Content; }
/// <summary> /// This constructor creates a think and do popup for either the first or second star number /// </summary> /// <param name="thinkAndDo">Desired think and do</param> /// <param name="starNumber">Enter 1 for Star Number 1 or 2 for Star Number 2</param> public ThinkAndDoPopup(ThinkAndDo thinkAndDo, int starNumber) { InitializeComponent(); ThinkAndDoTitle.Text = starNumber == 1 ? thinkAndDo.Text1 : thinkAndDo.Text2; lastClickedStarNumber = starNumber; lastClickedThinkAndDoName = thinkAndDo.ThinkAndDoName; //June 2019: moved the player init to the top of the file to be able to calculate duration later on ObjCRuntime.Class.ThrowOnInitFailure = false; player = Plugin.SimpleAudioPlayer.CrossSimpleAudioPlayer.CreateSimpleAudioPlayer(); string audioFile = starNumber == 1 ? thinkAndDo.ThinkAndDoAudioClip1 : thinkAndDo.ThinkAndDoAudioClip2; player.Load(audioFile); ImageButton button = new ImageButton() { Source = "pause.png", BackgroundColor = Color.Transparent }; ImageButton button2 = new ImageButton() { Source = "play.png", IsVisible = false, BackgroundColor = Color.Transparent }; Label displayLabel = new Label { Text = "0:00", TextColor = Color.White }; Slider slider = new Slider { Maximum = player.Duration, Minimum = 0, Value = 0, HorizontalOptions = LayoutOptions.FillAndExpand, HeightRequest = 50 // Controls size of area that can grab the slider }; ImageButton close = new ImageButton() { Source = "CloseButton", BackgroundColor = Color.Transparent }; close.Clicked += (sender, args) => { CloseAllPopup(); }; //here is where we should add logic for what happens when playback ends player.PlaybackEnded += MarkAsPlayed; bool audioFromTimer = false; bool playAudio = true; player.Play(); button.Clicked += (sender, args) => { player.Pause(); playAudio = false; button.IsVisible = false; button2.IsVisible = true; }; button2.Clicked += (sender, args) => { player.Play(); playAudio = true; button.IsVisible = true; button2.IsVisible = false; }; Device.StartTimer(new TimeSpan(0, 0, 1), () => { if (playAudio) { audioFromTimer = true; slider.Value += 1; } return(true); }); slider.ValueChanged += (sender, args) => { if (player != null) { int minutes = (int)args.NewValue / 60; int seconds = (int)args.NewValue - (minutes * 60); Console.WriteLine(args.NewValue); Console.WriteLine(player.CurrentPosition); Console.WriteLine(args.NewValue); if (!audioFromTimer) { player.Seek(args.NewValue); } String second = seconds.ToString(); if (seconds < 10) { second = '0' + seconds.ToString(); } displayLabel.Text = String.Format("{0}:{1}", minutes, second); var timeStamp = new TimeSpan(0, minutes, seconds); audioFromTimer = false; } }; StackLayout audio = new StackLayout { Orientation = StackOrientation.Horizontal, Children = { button, button2, displayLabel, close } }; TopStack.Children.Add(slider); TopStack.Children.Add(audio); }