//method to pause the audio file void Pause_Clicked(object sender, System.EventArgs e) { if (player.IsPlaying) { player.Pause(); } }
//event handler for MLK button on click //when the button is clicked: private void btnMLK_Clicked(object sender, EventArgs e) { if (playerMLK.IsPlaying) //if the MLK speech is playing, pause it { playerMLK.Pause(); } else //otherwise: { if (playerMalcolmX.IsPlaying) //if the malcolmx speech is playing: { playerMalcolmX.Pause(); //pause the malcolm x speech } playerMLK.Play(); //then play the MLK speech } }
public void TogglePause() { if (_simpleAudioPlayer.IsPlaying) { _simpleAudioPlayer.Pause(); } else { _simpleAudioPlayer.Play(); } }
public void Pause() { if (player.IsPlaying) { player.Pause(); } else { player.Play(); } }
private void ChangeState() { if (!_isMusicOn) { Player.Pause(); return; } if (!Player.IsPlaying && _isMusicOn) { Player.Play(); } }
private void Play_Clicked(object sender, EventArgs e) { if (AudioPlayer.IsPlaying) { AudioPlayer.Pause(); itemPlay.IconImageSource = ImageSource.FromResource("KeertanPothi.images.Play.png"); } else { AudioPlayer.Play(); itemPlay.IconImageSource = ImageSource.FromResource("KeertanPothi.images.Pause.png"); } }
public void onClickedPlay(object sender, EventArgs e) { if (player.IsPlaying) { playButton.Text = "Play"; player.Pause(); } else { playButton.Text = "Pause"; player.Play(); } }
public async void OnSleep() { if (darknetService.ConnectionState == DarknetService.ConnectionStatus.Connected) { darknetService.Disconnect(); } while (Navigation.NavigationStack.Count > 1) { await Navigation.PopAsync(); } particleManager.Enabled = false; player.Pause(); }
// Public Player Functions public void PlayPause() { if (PlayPauseState) { PlayPauseIcon = IconFont.PlayArrow; PlayPauseState = false; _player.Pause(); UpdatePosition(); } else { PlayPauseIcon = IconFont.Pause; PlayPauseState = true; _player.Play(); Device.StartTimer(TimeSpan.FromSeconds(0.7), UpdatePosition); } }
public void OnImgPausePlayTap(object sender, EventArgs e) { var objAudioDataSender = sender as Image; var SelectedTourAudio = objAudioDataSender.BindingContext as TourLocation; Xamarin.Forms.FileImageSource objFileImageSource = (Xamarin.Forms.FileImageSource)imgPausePlay.Source; if (objFileImageSource.File == "play_icon.png") { UpdateCurrentTimeofAudio(); player.Play(); imgPausePlay.Source = "pause_icon.png"; } else { player.Pause(); imgPausePlay.Source = "play_icon.png"; } }
private void PlayButtonClicked(object sender, EventArgs e) { if (playButton.ActionType == ACTION_START) { paused = false; player.Play(); slider.Maximum = player.Duration; slider.IsEnabled = player.CanSeek; SetPauseButtonStyle(); Device.StartTimer(TimeSpan.FromSeconds(0.5), UpdateSliderPosition); } else if (playButton.ActionType == ACTION_STOP) { paused = true; player.Pause(); SetPlayButtonStyle(); } }
private void OnFinishTime(object sender, ElapsedEventArgs e) { if (WaitForAnswer) { Player.Pause(); StartAnswerTimer(); } else if (CurrentVerseIndex == Lyrics.Count) { CurrentVerse = string.Empty; LyricTimer.Enabled = false; } else { UpdateLyric(); WaitForAnswer = CurrentVerse.Contains("*"); } }
private void PlayButtonClicked(object sender, EventArgs e) { if (_icon == 1) { PlayBtn.Icon = "md-pause"; _player.Play(); Slider.Maximum = _player.Duration; Slider.IsEnabled = _player.CanSeek; Device.StartTimer(TimeSpan.FromSeconds(0.5), UpdatePosition); _player.Loop = true; _icon = 2; } else { PlayBtn.Icon = "md-play-arrow"; _player.Pause(); _icon = 1; } }
public async void PlayTapped(object sender, EventArgs e) { if (player.IsPlaying) { PlayPauseSvg.Source = "Play.svg"; player.Pause(); } else { PlayPauseSvg.Source = "Pause.svg"; player.Play(); MainSlider.Maximum = player.Duration; Duration = player.Duration; Populate(Current); Device.StartTimer(TimeSpan.FromSeconds(0.5), UpdatePosition); } }
public SongPlayerPageViewModel(INavigationService navigationService, IPageDialogService pageDialogueService, IDeezerApiService apiService) : base(navigationService, apiService) { var stream = GetStreamFromFile("Nameofmp3.mp3"); player = Plugin.SimpleAudioPlayer.CrossSimpleAudioPlayer.CreateSimpleAudioPlayer(); player.Load(stream); GetTrackInfoCommand = new DelegateCommand(async() => { await GetTrackData(); }); PreviousPageCommand = new DelegateCommand(async() => { await navigationService.GoBackAsync(); }); ShareTrackCommand = new DelegateCommand(async() => { await CrossShare.Current.Share(new ShareMessage { Title = $"Hey check this song out! - {TrackInfo.Title}", Url = $"{TrackInfo.Share}" }); }); PlayTrackCommand = new DelegateCommand(async() => { player.Play(); }); PauseTrackCommand = new DelegateCommand(async() => { player.Pause(); }); }
private void BtnPauseClicked(object sender, EventArgs e) { player.Pause(); }
public void Pause() { player.Pause(); }
/// <summary> /// Pauses the song on the audio player. /// </summary> public static void PauseSong() { player.Pause(); }
protected void Pause() { _player.Pause(); _isPaused = true; }
public Menu() { InitializeComponent(); darknetService = DarknetService.Create(); darknetService.Settings = new DarknetSettings() { Resolution = darknetService.CameraPreview.SupportedResolutions.OrderBy((res) => res.Width * res.Height).First() }; particleManager = new ParticleManager(absLayout) { Enabled = false }; BackgroundImage = "background.jpg"; startDetectionButton = new MenuButton("StartDetectionWhite.png") { IsEnabled = false }; customizeFilterButton = new MenuButton("CustomizeFilterWhite.png") { IsEnabled = false }; trainNetworkButton = new MenuButton("TrainNetworkWhite.png") { IsEnabled = false }; optionsButton = new MenuButton("OptionsWhite.png"); disconnectButton = new MenuButton("DisconnectWhite.png"); connectButton = new MenuButton("ConnectWhite.png"); starButton = new ToggleButton("Stern.png", false); volumeButton = new ToggleButton("LautstaerkeButton.png"); volumeSlider = new Slider(0, 1, 1) { ThumbColor = Color.AliceBlue }; cyberDogImage = new Image() { Source = "cyber_dog.png", Scale = 0 }; AbsoluteLayout.SetLayoutBounds(cyberDogImage, new Rectangle(0, 0, 1, 1)); AbsoluteLayout.SetLayoutFlags(cyberDogImage, AbsoluteLayoutFlags.All); absLayout.Children.Add(cyberDogImage); toolbarGrid = new Grid(); toolbarGrid.RowDefinitions.Add(new RowDefinition { Height = new GridLength(1, GridUnitType.Auto) }); toolbarGrid.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(1, GridUnitType.Auto) }); toolbarGrid.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(1, GridUnitType.Auto) }); toolbarGrid.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(1, GridUnitType.Star) }); toolbarGrid.Padding = new Thickness(0, 0, 0, 0); toolbarGrid.Margin = new Thickness(0, 0, 0, 0); toolbarGrid.Children.Add(starButton, 0, 0); toolbarGrid.Children.Add(volumeButton, 1, 0); toolbarGrid.Children.Add(volumeSlider, 2, 0); grid.Children.Add(startDetectionButton, 0, 0); grid.Children.Add(optionsButton, 0, 1); grid.Children.Add(customizeFilterButton, 0, 2); grid.Children.Add(trainNetworkButton, 0, 3); grid.Children.Add(connectButton, 0, 4); grid.Children.Add(toolbarGrid, 0, 5); player = Plugin.SimpleAudioPlayer.CrossSimpleAudioPlayer.Current; player.Load("mainMenu.mp3"); player.Loop = true; player.Play(); // Handler starButton.ToggleChanged += (o, e) => { if (e) { particleManager.Enabled = true; } else { particleManager.Enabled = false; } }; volumeButton.ToggleChanged += (o, e) => { if (e) { player.Play(); } else { player.Pause(); } }; volumeSlider.ValueChanged += (o, e) => { player.Volume = volumeSlider.Value; }; connectButton.ClickedAnimationFinished += (o, e) => { connectButton.IsEnabled = false; if (darknetService.ConnectionState == DarknetService.ConnectionStatus.Disconnected) { darknetService.Connect(); } }; disconnectButton.ClickedAnimationFinished += (o, e) => { disconnectButton.IsEnabled = false; if (darknetService.ConnectionState == DarknetService.ConnectionStatus.Connected) { darknetService.Disconnect(); } }; optionsButton.ClickedAnimationFinished += (o, e) => Navigation.PushAsync(new SettingsPage(darknetService)); startDetectionButton.ClickedAnimationFinished += (o, e) => Navigation.PushAsync(new PreviewPage(darknetService)); customizeFilterButton.ClickedAnimationFinished += (o, e) => Navigation.PushAsync(new ClassFilterPage(darknetService)); darknetService.ClassCollectionAquired += (o, e) => { if (e != null) { Device.BeginInvokeOnMainThread(() => customizeFilterButton.IsEnabled = true); if (darknetService.FilteredClasses == null) { darknetService.FilteredClasses = new List <string>(); foreach (var obj in e.classes) { darknetService.FilteredClasses.Add(obj); } } } }; darknetService.Connected += (o, e) => { darknetService.SendSettings(); Device.BeginInvokeOnMainThread(() => { if (grid.Children.Contains(connectButton)) { grid.Children.Remove(connectButton); grid.Children.Add(disconnectButton, 0, 4); } disconnectButton.IsEnabled = true; startDetectionButton.IsEnabled = true; }); cyberDogImage.ScaleTo(1, 250); }; darknetService.Disconnected += (o, e) => { Device.BeginInvokeOnMainThread(() => { if (grid.Children.Contains(disconnectButton)) { grid.Children.Remove(disconnectButton); grid.Children.Add(connectButton, 0, 4); } connectButton.IsEnabled = true; startDetectionButton.IsEnabled = false; }); cyberDogImage.ScaleTo(0, 250); }; }
public Task Pause() { _audioStreamPlayer.Pause(); return(Task.Delay(0)); }
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); }
private void Button_Clicked_1(object sender, EventArgs e) // pause { player.Pause(); }
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; }
public void PauseClicked(object sender, EventArgs args) { player.Pause(); }
public StoryPage(Story story) { Story = story; StoryId = story.StoryId; StorySet = story.StorySetAsEnum; //pull the corresponding images out of the database var realmFile = Realm.GetInstance(RealmConfiguration.DefaultConfiguration); StoryPages = realmFile.All <RealmObjects.StoryPart>().Where(x => x.StoryId.Equals(story.StoryId)) .OrderBy(x => x.Order).ToList(); //get the current user's ID - if we ever want multiple users per device, we'll have to store the user's id in RAM var userId = realmFile.All <User>().FirstOrDefault().UserId; //init user story transaction using (var writer = realmFile.BeginWrite()) { UserStoryTransaction = new UserStoryReads(); UserStoryTransaction.StoryId = StoryId; UserStoryTransaction.UserId = userId; UserStoryTransaction.StartReadTime = DateTime.UtcNow; //add to the db realmFile.Add <UserStoryReads>(UserStoryTransaction); writer.Commit(); } InitializeComponent(); PlayButton.Source = PAUSE_ICON; //set at the pause icon because this page auto-starts PlayButton.HeightRequest = 40; PlayButton.WidthRequest = 50; PlayButton.BorderColor = Color.Transparent; PlayButton.BackgroundColor = Color.Transparent; PlayButton.Margin = 20; QuizButton.Source = "Quizzes.png"; QuizButton.BackgroundColor = Color.Green; QuizButton.IsVisible = false; DurationLabel.Text = "0:00"; DurationLabel.FontFamily = Device.RuntimePlatform == Device.Android ? "Comic.ttf#Comic" : "Comic"; DurationLabel.Margin = 20; CurrentStoryPage = StoryPages.First(); //story content StoryImage.Source = CurrentStoryPage.Image; StoryImage.MinimumWidthRequest = DeviceDisplay.MainDisplayInfo.Width; StoryImage.Aspect = Aspect.AspectFit; player = Plugin.SimpleAudioPlayer.CrossSimpleAudioPlayer.Current; player.Load(story.AudioClip); //find the story duration if we haven't already if (story.DurationInSeconds <= 0) { using (var transaction = realmFile.BeginWrite()) { story.DurationInSeconds = player.Duration; transaction.Commit(); } } //kill the realm file to help with memory consumption realmFile.Dispose(); realmFile = null; //slider init StoryPageSlider.Maximum = story.DurationInSeconds; StoryPageSlider.Minimum = 0; StoryPageSlider.Value = 0; StoryPageSlider.HorizontalOptions = LayoutOptions.FillAndExpand; //StoryPageSlider.MinimumWidthRequest = DeviceDisplay.MainDisplayInfo.Width - (PlayButton.Width * 4); StoryPageSlider.HeightRequest = 50; // Controls size of area that can grab the slider //use drag completed instead of value changed to avoid "stuttering" audio StoryPageSlider.DragCompleted += UserDraggedSlider; //register action to be taken once the story ends player.PlaybackEnded += EndPlayback; player.Loop = false; //start the player in a different thread var playerThread = new Thread(new ThreadStart(() => { //this starts the audio player.Play(); })); playerThread.Start(); PlayButton.Clicked += (sender, args) => { //toggle play/pause if (player.IsPlaying) { player.Pause(); PlayButton.Source = PLAY_ICON; } else { player.Play(); PlayButton.Source = PAUSE_ICON; } }; RefreshStoryPagesTimer(); QuizButton.Clicked += (sender, args) => { //Navigation.PushAsync(new QuizPage(story.Quizzes[quizNum], story.AudioClip)); }; }
/// <summary> /// Plays audio /// </summary> /// <param name="sender"></param> /// <param name="e"></param> public void PauseClicked(object sender, EventArgs e) { player.Pause(); AudioButton.Text = "Play"; AudioButton.Clicked += PlayClicked; }
/// <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); }