I am using the AudioKit's AudioPlayer!. My earlier version of the code had
audioPlayer.isPlaying flag to check if the player is still playing or paused/stopped. Now that isPlaying flag has been removed, can someone please guide me on what is the equivalent code?
thanks,
-Vittal
Try isStarted
From AudioPlayer+Playback:
/// Synonym for isPlaying
public var isStarted: Bool { status == .playing }
Related
I am playing a live stream using AVPlayer and AVPlayerItem.
Is there a way to know if the user has muted/unmuted the video while playing it
You can check the isMuted value of the AVPlayer.
Documentation:
https://developer.apple.com/documentation/avfoundation/avplayer/1387544-ismuted
You can use a combination of KVO and Combine to observe changes to isMuted property:
let player: AVPlayer
private var cancellables = Set<AnyCancellable>()
//...
player
.publisher(for: \.isMuted)
.sink { isMuted in
// here you can handle the fact the the user has muted or unmuted the player
}
.store(in: &cancellables)
You should implement KVo to detect mute/unmute changes.
Note: in swift, although the property is isMuted, but you still should use ObjectiveC properties in KVo, so listen for muted key and you are set.
I am experimenting with other sound effect options for our game after determining SKAction.playSoundFileNamed is not only buggy and leaky but also creates a crash specifically during IAP interruptions (not OK, Apple). We are attempting to use SKAudioNodes, but the issue is we have overlapping sound effects. We would like to use a system whereby we have a queue of SKAudioNodes that exist with the identical effect: e.g. audioNode1, audioNode2, audioNode3, all with sound "fxmatch," and if audioNode1.isPlaying(), then we will move on in the queue to audioNode2, then audioNode3, etc. We have similar syntax already for AVAudioPlayer, where we check isPlaying(). Is there some method equivalent for SKAudioNodes?
if let playerNode = audioNode.avAudioNode as? AVAudioPlayerNode{
print(playerNode.isPlaying)
}
Or
extension SKAudioNode
{
var isPlaying : Bool { return (avAudioNode as? AVAudioPlayerNode)?.isPlaying ?? false }
}
...
print(audioNode.isPlaying)
As Apple said in iOS 9.3 we can Access Apple Music Library. I am playing it from my application by MPMusicPlayerController.
I am getting wrong playbackState. For Ex. If song continue playing - so it should return status MPMusicPlaybackStatePlaying but gettting other enum values. My code is
if ([[MPMusicPlayerController systemMusicPlayer] playbackState]==MPMusicPlaybackStatePlaying)
{
}
else
{
NSLog(#"playbackState %ld",(long)[[MPMusicPlayerController systemMusicPlayer] playbackState]);
}
As apple saying here we have following possible vales -
Values for the playbackState property.
Declaration
Objective-C
enum {
MPMusicPlaybackStateStopped,
MPMusicPlaybackStatePlaying,
MPMusicPlaybackStatePaused,
MPMusicPlaybackStateInterrupted,
MPMusicPlaybackStateSeekingForward,
MPMusicPlaybackStateSeekingBackward
};
typedef NSInteger MPMusicPlaybackState;
How will I get the correct state of current playing song . Any Idea, If I mistaken something please let me know. Thanks
It is insane but this works:
_ = systemMusicPlayer.currentPlaybackRate
DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) { [weak self] in
print(self?.systemMusicPlayer.playbackState)
}
I've also faced this issue. So the workaround is: every n seconds check the [[MPMusicPlayerController systemMusicPlayer] currentPlaybackRate] property. 1 corresponds to "playing" and 0 to "paused" (or stopped).
I want to toggle between two images to pause and play my game. I tried using the code below but it doesn't work. I declared the pause and play as SKSpriteNodes().
Can anyone help?
func paused(){
self.scene?.view?.paused = true
pause.removeFromParent()
}
// PLAYING FUNCTION
func playing(){
self.scene?.view?.paused = false
play.removeFromParent()
}
As someone else told you, you aren't giving enough informations for us to give you a precise answer.
Anyway, the little part of your code that I can see doesn't seem to be right to me.
First of all you probably shouldn't use two nodes, nor delete any of them.
If your goal is simply to change the icon, you should use the same node and simply change its texture property.
If you'd like an example, I can give you one.
EDIT : Here is the example
// In this example, we will call playPauseNode the SKSpriteNode you are using as a button
var isPlaying = true
func buttonTouched() {
if isPlaying { // If the game is playing
playPauseNode.texture = SKTexture(imageNamed: "theNameOfYourPlayButtonImage")
isPlaying = false
}
else { // If the game is paused
playPauseNode.texture = SKTexture(imageNamed: "theNameOfYourPauseButtonImage")
isPlaying = true
}
}
I believe it should behave as you expect it to...
By looking at reference, there is no explicit solution - some property or a delegate callback...
But maybe there could be some trick, how to reliably ask the recorder to tell me whether it is paused. Sometimes the required information can be derived from the state of other properties..etc..
Of course I can store that "paused" information myself throughout the management of the whole recording session. But it's less reliable and I want to be sure, that its not possible as described above.
You could simply check for isRecording to be false, that would either mean that it is stopped or paused.
In SWIFT 2 you just check Booll property called recording:
if audioRecorder.recording{
print("recording")
}else{
print("not recording")
}
You can check a boolean value isRecording that indicates whether the audio recorder is recording.
if audioRecorder.isRecording {
// AudioRecorder is recording.
} else {
// AudioRecorder is not recording.
}