AVPlayer strange behaviour - ios

I use an avplayer instance to play a movie that plays forward and backward, depending on the device's roll. I use the rate at 1/-1 for that. Besides some lagging when rewinding, I have an awkward effect every some seconds. It seems as the movie is kind of reloaded and zoomed back into the view.
Observing status, rate and duration values show no additional execution of anything, memory consumption is stable, initialisation is not repeated either.
I didn't find anything, but does the avplayer has something like a sleep mode? auto reload?
Any ideas at what to look into would be much appreciated.

Related

truncated sound clips on IOS

The essence of the problem is that on IOS only, playing
sound clips using
MediaManager.createMedia(clip, "audio/wav", null).play();
sometimes the playback is truncated. This is especially obvious
when the clip is several seconds long, but the point at which the
clip is truncated varies; occasionally the whole clip plays.
I've so far been unsuccessful creating a simple test case - in isolation
from my apps, the clip plays in full, so it seems like something in normal
background activity in the full app is interfering with audio playback.
I'm pretty sure I've found the root cause. MediaManager.createMedia creates an instance of Media, and when that object is garbage collected, it's finalize method is called, and a side effect of that causes the audio to be stopped.
A quick and dirty way to prevent this is to save a pointer to the media object.
This ought to be accomplished by internal bookkeeping in playaudio.

AVPlayer smooth seekToTime

Is where a way to smoothly seek playback to some position?
In other words, imagine that some track playing at 0:53 and I need it to play at 0:58 after 2 seconds. So I need it to smoothly increase rate (like using easing functions in animation) and smoothly decrease rate when playback time almost equal 0:58. (it should sound like rewind effect)
Simple seekToTime method is not an option since it just jumps to position.
Here is an illustration:
two________________________seconds_________________________to_seek
0:53__________________________________________________________0:58
|____________↑_________|__________=_________|__________↓__________|
rate=1______smoothly_rate=2.0_______________smoothly_rate=1_____rate=1
I've already tried to use easing methods to smoothly increase rate but looks like it's impossible - rate value changes right away to desired value without easing.
At least I know that it is actually possible. You can try Ampme app from Appstore. They're playing music synchronously on different devices and if there is some lag (buffering, etc) on one of the devices, it's playback smoothly corrects to right value without jumping.
Currently I'm using setRate:time:atHostTime: method and I think it's the right way, but I'm not able to make it work seeking smoothly.

Transitioning to background, AVPlayer Video has small audio gap

I have followed the many helpful previous questions to get my AVPlayer successfully streaming video when my app goes to the background. There are two methods described on Apple's QA1668 and they both work for my stream urls.
The problem is that there is a noticeable audio gap during the transition that is identical for both methods. On my iPhone 6 in release mode I would say the gap is less than 0.5 seconds, which may not seem terrible but if I'm playing something like a music video this is very distracting.
After more testing it looks like this gap actually occurs when I remove the AVPlayerLayer (or, if I am using the other method, when I disable the AVMediaCharacteristicVisual tracks) as I have determined it will still happen if I hook those actions up to a button rather than the backgrounding state.
My guess is that is has something to do with the audio re-syncing to the new video state of the AVPlayer but really I have no clue. Any help would be greatly appreciated!

AVPlayer setRate property create glitchy if we use setRate frequently

I have used AVPlayer to play videos in slow motion. I am using addPeriodicTimeObserverForInterval: message to get time at specific interval, and checking some condition according to current playback time. once condition is fulfilled, I am calculating rate and using setRate: message of AVPlayer. i.e I am setting rate frequently. but once I have done with this, video is not playing smoothly, it's glitchy.
Can anybody please let me know how can I set setRate: frequently.
Thanks
We were having kind of the same issue. We were using setRate:1 (or 1.5/2.0 depending on what the user chose) to play the video instead of calling play. We have changed to call play then setRate: and the video plays smoothly now.

MPMoviePlayerController blank frame after seeking to particular time-line

I am developing an iPhone application in which I play a video using MPMoviePlayerController. I use custom controls to play the video.
I have a slider that shows video time line. Using this user can seek the movie to any time-line of the movie.
When user continuously moves the slider:
Pause the video only for first time; [MPMoviePlayerController-obj pause]
MPMoviePlayerController-obj.currentPlaybackTime = slider.value
When slider action ends:
Play the video; [MPMoviePlayerController-obj play]
This plays the movie from the position where user had left the slider. But, it leads to blank frame when movie completes playing. This defect occurs randomly; i.e not for all the seek'd time.
What is the reason for getting the blank frame? How do I solve this?
I'm not sure if this will work, but try setting the initialPlaybackTime to either the slider.value or to currentPlaybackTime.
For being sure that your content is not flawed, hence possibly triggering that issue, you should try to replicate your faulty MPMoviePlayerController results using Apple's reference video content.
HTTP-Streaming: bipbop.m3u8
Progressive Download & Local
Playback: sample_mpeg4.mp4
I have personally observed many issues in connection with improper encoding. Weird things tend to happen when working with lossy compressed content. This is true for video (i-frames vs. p-frames) as well as audio (variable bitrate).
One being improper playback durations being reported. Such issue may result into an unexpected finished-state. I have seen cases where MPMoviePlayerController still shows a bunch of seconds to play even though the actual video has obviously finished. Those cases occur frequently once the user seeks around within the video.
Once you made sure that the issue occurs using the given sample files as well, you should file a bug-report.

Resources