pause the player - blackberry

i want to pause the player. but over code only perform start and stop. how we pause the player.

i think player.stop() will pause the player. according to blackberry docs.
public void stop()
throws MediaException Stops the Player. It will pause the playback
at the current media time.

Check the code in your start button. It probably calls setMediaTime(0) or something else is. Vivart is correct in that stop() is pause-- it just stops, it has nothing to say about the MediaTime inside the player.

Related

How can I pause SCNAudioPlayer playback in ARKit?

I'm trying to implement a play/pause button for positional audio attached to a node in an ARKit scene. I want the user to be able to pause the audio, then resume it from the paused point at a later time. So removeAudioPlayer() is no good, as this resets the audio back to the start when it is reattached.
The only pause method associated with SCNAudioPlayers that I can find is buried deep down in:
myAudioPlayer.audioNode?.engine?.pause()
But this doesn't seem to have any effect. Strangely
myAudioPlayer.audioNode?.engine?.stop()
Does stop the audio from playing, but then you can't start it again afterwards!
My code for creating the audioPlayer is as follows:
audioSource = SCNAudioSource(fileNamed: "audio.caf")!
audioSource.loops = false
audioSource.isPositional = true
audioSource.shouldStream = false
audioSource.load()
// then a bit later...
audioPlayer = SCNAudioPlayer(source: audioSource)
myARNode.addAudioPlayer(audioPlayer)
Notice that no 'play' method is needed. The audio just starts playing as soon as you attach it to the node. And the lack of straight play() and pause() methods as top-level properties of SCNAudioPlayer makes me wonder if it's possible at all. This seems slightly crazy however, as it's a pretty rudimentary aspect of working with audio.
Does anyone know if this can be done?
Thanks in advance.
To stop audio engine use 2 sec delay. Pause doesn't work here (I'm using Xcode 12.2).
DispatchQueue.main.asyncAfter(deadline: .now() + 2.0) {
player.audioNode?.engine?.stop()
}

In which cases avplayer should play? Like play() function, set player rate

I set player to pause and i am setting player rate after the pause. After setting player rate avplayer starting the playing without play() method, so i want to know in which other cases that avplayer should play without play() method.
I find that when we set rate or seek to specific time than it is play but i want to know is there other cases when avplayer should play.
Please check https://github.com/teamSolutionAnalysts/sa-plug-avplayer which is very easy plug and play module, lets you play video easily and you tube embedded url supported.

Detect end of playback on lock screen - AVPlayer

I've the array of audio file and would like to play them consecutively. Is there any way to detect when AVPlayer ending playing on lock screen so that I could call a completion handler and play next sound? I want to call nextPlayAudio() from my PlayerViewController class. I am fire notification after finishing current playback audio but nextPlayAudio() not get called after finishing.
Use the AVPlayerItemDidPlayToEndTime notification to manage this.
Example as a service here: https://github.com/noreasonprojects/ModernAVPlayer/blob/develop/Sources/Core/Services/PlaybackObservingService.swift
| Check the PlayingState file, where the service is used.

Resuming play of live video stream after AVPlayerItemFailedToPlayToEndTime

If some error happens on the server side (playlist) of HLS, the AVPlayer client will eventually stop and we will get this notification: AVPlayerItemFailedToPlayToEndTime.
How can we resume play after this, taking for granted that all errors serverside are fixed?
I cause 500 errors on the playlist side. The AVPlayer stops after a while.
Even after AVPlayerItemFailedToPlayToEndTime has happened, the status of the AVPlayer is NOT failed, and the currentItem.status is also NOT failed. Specifically both of these are still readyToPlay which looks like we SHOULD be able to continue playing without recreating the whole AVPlayer instance etc.
The way I try to cause a "play" again is self.play() (subclass of AVPlayer). This does not work.
I've been able to resume play (from a failed state) by recreating the AVPlayerItem and assigning it again using replaceCurrentItem(). However since I need this to happen without any user interaction (like pressing play button etc), it seems like there is no good way to find out WHEN to apply this method, and if it really worked or not.
I think you need to save your pause time. Whenever you have yo play video again, say 'Play Button Click' OR 'Resume Video' , seek to that time
avPlayer.seek(to: playerPauseTime)
if self.avPlayer.status == .readyToPlay && self.avPlayer.currentItem?.status == .readyToPlay {
self.avPlayer.seek(to: atTime,
toleranceBefore: kCMTimeZero,
toleranceAfter: kCMTimeZero,
completionHandler: { (finished) in
self.avPlayer.play()
})
}
And you will be playing your video from time lapse where it was paused.

AVFoundation AVAudioPlayer stop is pausing - Objective-C

It's fairly hard to show code for this as it is not noticeable in the code. I have some actions like -(IBAction)PlaySound1:(id)sender; and -(IBAction)PlaySound2:(id)sender; and audio files. I have the sounds working all fine. I also have -(void)Stop;. When Play sound 1 is pressed it calls the method Stop and stops sound 2. and the same with sound 2.
The problem I am encountering is when you play sound 1 and stop sound 2, when you play sound 2 it starts from where it left off.
Inside my (void) I have [PlaySound1 stop] //and [PlaySound2 stop]
If anyone could help that would be great. If something was unclear, just comment on this and I'll try and explain it better.
Thanks :)
Stopping an AVAudioPlayer does not reset the play head.
The stop method does not reset the value of the currentTime property to 0. In other words, if you call stop during playback and then call play, playback resumes at the point where it left off.
To resume playback from the start set the currentTime property to 0.0 before calling play.
example -
playSound2.currentTime = 0.0;
[playSound2 play];

Resources