private SoundChannel playIos(double startTime = 0, int loops = 0, SoundTransform sndTransform = null) { if (null == _player) { return(null); } if (loops < 0) { loops = 0; } _player.NumberOfLoops = loops; if (startTime > 0) { _player.PlayAtTime(startTime); } else { _player.Play(); } return(_channel); }
public void PlayAtTime(double time) { player.PlayAtTime(time); //TODO: Avoid repetition. Move into some post-construct phase. if (timer == null) { timer = NSTimer.CreateRepeatingScheduledTimer(1, delegate { PositionChanged?.Invoke(this, new EventArgs()); }); } }
private SoundChannel internalPlay(double startTime = 0, int loops = 0, SoundTransform sndTransform = null) { // Instead of doing this every frame, we only do it when we play a new sound (it is less often) // This still gives us opportunity to recycle audio players before a new one is needed RemoveUnusedAudioPlayers(); if (null == mPlayer && _url != null) { internalLoad(_url); } if (null == mPlayer) { DebugTrace("Could not load sound " + (_url != null ? _url : "<unknown>")); return(null); // If we could not still load it, probably should add an error message } DebugTrace("Play sound " + _url); if (sPlayingSounds.Count >= MaxNumberOfPlayingSounds) { // Too many sounds, if that's mp3, we assume it is music, and in that case we don't skip this one... if (_url.EndsWith(".mp3", StringComparison.InvariantCultureIgnoreCase) == false) { if (IsInPlayingList() == false) { DebugTrace(" Unloaded."); unload(); // We can safely unload it if it is not in the playlist already } DebugTrace(" Skipped."); return(null); } } // We add it to the playing sounds only if it does not actually plays if (IsInPlayingList() == false) { // Not already in the list, add it and play it Debug.Assert(mPlayer.Playing == false); CheckInPlayingList(false); sPlayingSounds.Add(this); CheckInPlayingList(true); if (sPlayingSounds.Count >= ReportNumberOfPlayersAbove) { GeneralDebugTrace(sPlayingSounds.Count.ToString() + " sounds playing simultaneously."); } } mPlayer.NumberOfLoops = (loops > 0) ? loops : 0; if (mPlayer.Playing == false) { //DispatchQueue.DefaultGlobalQueue.DispatchAsync (() => { if (startTime > 0) { mPlayer.PlayAtTime(startTime); } else { mPlayer.Play(); } //}); } else { DebugTrace(" Was already playing."); } return(mChannel); }
partial void BtnPlayPause_TouchUpInside(UIButton sender) { ControlMusic(IsMusicPlaying); player.PlayAtTime(1000); }