I am have implemented PIP in my app. When user goes to background while video was playing. App opens PIP and everything works fine. But when user locks the device , PIP is not stopping/Pausing the video.
Is there a way I can pause the Video when user locks the device?
Media Player
RSS for tagFind and play songs, audio podcasts, audio books, and more from within your app using Media Player.
Posts under Media Player tag
72 Posts
Sort by:
Post
Replies
Boosts
Views
Activity
I wanted to report an issue I've encountered with the latest Beta 6 update concerning the immersive space feature. Before this update, when I was in immersive space and clicked on a window button to play a video using AVPlayer, I had the option to keep other windows open and accessible within the environment. Could you please investigate this issue? It would be helpful to know if this is an intentional change or if there might be a bug affecting window management in immersive space.
Thank you for your attention to this matter. I look forward to your response.
I just updated to IOS 18.0 Beta last night and this morning tried to launch Apple Podcast app and it will not load at all. It’s stuck in the “updating library“ with the spinning wheel icon. it was working just fine last night before I chose to update. Is there a known fix or am I better off going back to IOS 17?
Media Player album artwork images do not release memory after loading so memory accumulates, eventually impacting performance and causing crashes.
Steps To Reproduce:
Download example project and run on device
Grant access to library of 100+ albums
Scroll through albums on any tab screen
Observe steady memory increase in Xcode debug navigator and crash as you scroll
Observe same memory accumulation on other screens that use different methods to get album artwork images
Observations:
Various methods of obtaining album artwork insufficiently release memory and impact app performance.
1 - Artwork Image releases memory sometimes if the images are small and you scroll slow, but app will still accumulate memory, drop frames when scrolling, and eventually crash.
2 - Value For Property behaves similar to Artwork Image even when using the implicit size of the artwork bounds.
3 - Image From Disk problem seems related to perform() method since you can remove UIImage and memory still accumulates
All 3 methods result in higher retain counts than expected for artwork objects that could be preventing memory from releasing
Is there anyway we can add volume controls to adjust the volume settings from our phone? I’ve noticed we have to reply on the radio head unit to control our volume when it comes to our navigation and music. we should have full access to control it from our phone as well. Any thoughts?
Audio getting disabled, Not able to control audio, When opening music player audio works but not on instagram or any other apps.
Audio button on notification bar is greyed out as getting disabled.
I am stuck with some of my downloaded books not syncing correctly. A book that imported correctly to my library on Mac (7h of audio), only syncs to my iPhone as 4min audio. And I just can't find a way to make it work... All the sync is switched on in iCloud, but I sync them via cable anyway. Books downloaded as singular file seem to work, but books downloaded as chapters are not syncing correctly.
My suspicion is either:
Books that are downloaded as individual chapters only carry over the first chapter to the iPhone (why?!)
iPhone runs on iOS18 Beta, while the Mac is still on Sonoma 14.5, which may be causing the issue (?)
or something else entirely, that I am unaware of...
Anyway, any input, helpful articles or advice how to sort this out would be much appreciated!
Thanks.
Hello !
I am working on an app connected to an external streamer .
I would like to display current playing song on the Lock Screen.
I tried to update the information in MPNowPlayingInfoCenter but I need to play a sound on my iPhone for the control to be displayed .
Is there a way to do it without playing a sound?
If not, playing a silent sound would be the only solution ? validated by Apple ? :-/
Thank you
Frederic
I have a React website that uses getUserMedia to capture user audio. I'm displaying this website in an iOS mobile app using UIWebView in SwiftUI. The audio is correctly captured when the app is in focus. However, when the app goes to the home screen and runs in the background, the microphone audio gets cut off. This issue does not occur when the website is opened in iOS Safari.
Here's my Info.plist and .entitlements file. I granted most, if not all, permissions for both files in an attempt to get it to work, but it still doesn't resolve the issue.
Info.plist
audio
bluetooth-central
bluetooth-peripheral
external-accessory
fetch
location
nearby-interaction
processing
push-to-talk
remote-notification
voip
Entitlements.plist
com.apple.developer.push-to-talk: true
com.apple.developer.spatial-audio.profile-access: true
inter-app-audio: true
I have a user who is reporting an error and has been kind enough to share screen recordings to help diagnose. I am not experiencing this error, nor am I able to replicate on other devices I've tried, so I'm stuck trying to fix. His & other devices tested were all running iOS 17.5.1. Any details on the cause of this error or potential workarounds I could use to resolve would be greatly appreciated.
try await ApplicationMusicPlayer.shared.play()
throws:
The operation couldn't be completed (MPMusicPlayerControllerErrorDomain error 6.)
MusicAuthorization.currentStatus is .authorized
ApplicationMusicPlayer.shared.isPreparedToPlay is false
ApplicationMusicPlayer.shared.queue.currentEntry is nil (I've noticed this to be the case even when I am able to successfully play as well)
Queue was loaded using ApplicationMusicPlayer.shared.queue = [album] but I also tried ApplicationMusicPlayer.shared.queue = ApplicationMusicPlayer.Queue(album:startingAt:) and it made no difference. album.playParameters are correct. He experiences the error when attempting to play any album.
Any and all help is truly appreciated. Feedback Assistant filed has gone unanswered.
MPMusicPlayerControllers nowPlayingItem no longer seems to be able to change a song. The code use to work but seems to be broken on iOS 16, 17 and now the iOS 18 beta.
When newSong is triggered, the song restarts but it does not change songs. Instead I get the following error: Failed to set now playing item error=<MPMusicPlayerControllerErrorDomain.5 "Unable to play item <MPConcreteMediaItem: 0x9e9f0ef70> 206357861099970620" {}>.
The documentation seems to indicate I’m doing things correctly.
class MusicPlayer {
var songTwo: MPMediaItem?
let player = MPMusicPlayerController.applicationMusicPlayer
func start() async {
await MPMediaLibrary.requestAuthorization()
let myPlaylistsQuery = MPMediaQuery.playlists()
let playlists = myPlaylistsQuery.collections!.filter { $0.items.count > 2}
let playlist = playlists.first!
let songOne = playlist.items.first!
songTwo = playlist.items[1]
player.setQueue(with: playlist)
play(songOne)
}
func newSong() {
guard let songTwo else { return }
play(songTwo)
}
private func play(_ song: MPMediaItem) {
player.stop()
player.nowPlayingItem = song
player.prepareToPlay()
player.play()
}
}
Music app stops playing when switching to the background
In apps that play music or music files, if you move to the home screen or run another app while the app is running, the music playback stops.
Our app does not have the code to stop playing when switching to the background.
We are guessing that some people experience this and others do not.
We usually guide users to reboot their devices and try again.
How can this phenomenon be improved in the code?
Or is this a bug or error in the OS?
Hi,
since the IoT cybersecurity, I need to hide the version of all sevices.
For the 7000 port, AirTunes, I can't find the method to hide it.
Like tomcat version hide, how can I hide the version of it?
Just updated to macOS Sequoia Beta 2, and all the sudden my speakers start making a pop sound when I watch YouTube or just when browsing. Any tips?👀
I am writing to report an issue encountered with the playback of HLS (HTTP Live Streaming) streams that I believe is specific to iOS version 17. The problem manifests when certain conditions are met during the playback of concatenated HLS segments, particularly those with low video bitrate. Below, I will detail the background, symptoms, and steps required to reproduce the issue.
Background:
Our business scenario requires concatenating two HLS playlists, referred to as 1.m3u8 and 2.m3u8, into a single playlist 12.m3u8. An example of such a playlist is as follows:
#EXTM3U
#EXT-X-VERSION:3
#EXT-X-ALLOW-CACHE:YES
#EXT-X-TARGETDURATION:2
#EXT-X-MEDIA-SEQUENCE:0
#EXTINF:2.0,
1.1.ts
#EXTINF:2.0,
1.2.ts
#EXTINF:2.0,
1.3.ts
#EXT-X-DISCONTINUITY
#EXTINF:2.0,
2.1.ts
#EXTINF:2.0,
2.2.ts
#EXT-X-ENDLIST
Problem Symptoms:
On PC web browsers, Android devices, and iOS versions 13 and 15, the following is observed:
Natural playback completion occurs without any issues.
Seeking to different points within the stream (e.g., from 3 seconds to 9 seconds) works as expected.
However, on iOS version 17, there is a significant issue:
Natural playback completion is unaffected.
When seeking to various points within the first playlist (1.m3u8) after playing for 1, 2, or 3 seconds, the audio for the last 3 seconds of 1.m3u8 gets lost.
Conditions for Replication:
The issue only arises when all the following conditions are satisfied:
The video content is generated from a single image and an audio track, ensuring sound presence in the final 3 seconds.
The video stream bitrate is below 500 Kbps. (Tested with 1393 Kbps bitrate, which did not trigger the issue.)
The HLS streams are concatenated using the #EXT-X-DISCONTINUITY tag to form a virtual 11.m3u8 playlist. (No issues occur when streams are not concatenated.)
Seek operations are performed during playback. (No issues occur without seek operations.)
The issue is exclusive to iOS version 17. (No issues reported on iOS versions 13 and 15.)
Disrupting any one of these conditions results in normal playback behavior.
Steps to Reproduce:
Using FFmpeg, generate a video from a single image and an audio track, with a suggested duration of 10 to 20 seconds for testing convenience.
If the video's bitrate exceeds 1000 Kbps, consider transcoding it to 500 Kbps or lower to avoid potential edge-case issues.
Convert the 1.mp4 file into 1.m3u8 using FFmpeg. The segment duration can be set to between 1 and 5 seconds (tested with both 2-second and 5-second durations).
Duplicate 1.m3u8 as 2.m3u8, then concatenate 1.m3u8 and 2.m3u8 into 12.m3u8 as shown below:
#EXTM3U
#EXT-X-VERSION:3
#EXT-X-ALLOW-CACHE:YES
#EXT-X-TARGETDURATION:2
#EXT-X-MEDIA-SEQUENCE:0
#EXTINF:2.0,
1.1.ts
#EXTINF:2.0,
1.2.ts
#EXT-X-DISCONTINUITY
#EXTINF:2.0,
1.1.ts
#EXTINF:2.0,
1.2.ts
#EXT-X-ENDLIST
On an iOS 17 device, play 12.m3u8 for 1, 2, or 3 seconds, then seek to any point between 7 and 9 seconds (within the duration of 1.m3u8). This action results in the loss of audio for the last 3 seconds of 1.m3u8.
Hi.
I saw that in iOS 18 Beta there is a property "transition" on the Music Kit's ApplicationMusicPlayer. However, in my app I am using MPMusicPlayerApplicationController because I want to play Apple Music songs, local songs and podcasts. But I didn't find an analogue property on MPMusicPlayerApplicationController to specify transitions between songs. Am I missing something?
Thanks,
Dirk
Hello,
We are seeing some strange behaviour when using MPRemoteCommandCenter as well as UIKeyCommand in our app on iOS 17.
We are finding that when a UIKeyCommand is trigerred via external keyboard to start playing some music (via our own custom CoreAudio driver), the keyboard becomes unresponsive for a few seconds before UIKeyCommands are triggered again.
Strangely enough, if we comment out all our MPRemoteCommandCenter code, the UIKeyCommands work without going into the unresponsive state for a few seconds.
ie
UIKeyCommands:
override open var keyCommands: [UIKeyCommand] {
let commands = [UIKeyCommand(title: String(localized: "__PLAY_STOP__"), action: #selector(shortcutPlayStop(_:)), input: " "),
UIKeyCommand(title: String(localized: "__PAUSE__"), action: #selector(shortcutPause(_:)), input: "."), /** etc **/]
commands.forEach { $0.wantsPriorityOverSystemBehavior = true }
return commands
}
and MPRemoteCommands:
MPRemoteCommandCenter.shared().playCommand.addTarget { [weak self] _ in
self?.doStuff()
// etc
return .success
}
Note this issue did not occur prior to iOS17 🤨
Any ideas what could be going on?
Thank you!
Hello,
We've a music app reading MPMediaItem.
We got items using MPMediaQuery. But we realized that some downloaded tracks from Apple Music were fetched too. Not all downloaded track but only those who were played recently.
Of course, since these tracks are protected with DRM we can't play them in our player.
It's weird to get them in our query because we added predicate in order to dont fetch protected asset and iCloud item
MPMediaPropertyPredicate(value: false, forProperty: MPMediaItemPropertyHasProtectedAsset)
MPMediaPropertyPredicate(value: false, forProperty: MPMediaItemPropertyIsCloudItem)
To be sure, we made a second check on each item we've fetched
extension MPMediaItem {
public func isValid() -> Bool {
return self.assetURL != nil && !self.isCloudItem && !self.hasProtectedAsset
}
}
But we still get these items. Their hasProtectedAsset attribute always return false.
I dont know if it's a bug, but since we can't detect this items as Apple Music downloaded track, we can't either:
filter them to not add them in our application library
OR
switch on a MPMusicPlayerController.applicationMusicPlayer to allow the user to play them
Using the hardware volume buttons on the iPhone, you have 16 steps you can adjust your volume to. I want to implement a volume control slider in my app. I am updating the value of the slider using AVAudioSession.sharedInstance().outputVolume. The problem is that this returns values rounded to the nearest 0 or 5. This makes the slider jump around. .formatted() is not causing this problem.
You can recreate the problem using code below.
@main
struct VolumeTestApp: App {
init() {
try? AVAudioSession.sharedInstance().setActive(true)
}
var body: some Scene {
WindowGroup {
ContentView()
}
}
}
struct ContentView: View {
@State private var volume = Double()
@State private var difference = Double()
var body: some View {
VStack {
Text("The volume changed by \(difference.formatted())")
Slider(value: $volume, in: 0...1)
}
.onReceive(AVAudioSession.sharedInstance().publisher(for: \.outputVolume), perform: { value in
volume = Double(value)
})
.onChange(of: volume) { oldValue, newValue in // Only used to make the problem more obvious
if oldValue > newValue {
difference = oldValue - newValue
} else {
difference = newValue - oldValue
}
}
}
}
Here is a video of the problem in action:
https://share.icloud.com/photos/00fmp7Vq1AkRetxcIP5EXeAZA
What am I doing wrong or what can I do to avoid this?
Thank you
Since iOS 12 it has become difficult to detect the end of playback using the system music player.
In earlier iOS versions, the now playing item would be set nil and you would receive a notification that the player stopped.
In iOS 12 and later, nowPlayingItem still contains the current song and the only notification you get is MPMusicPlayerControllerPlaybackStateDidChangeNotification with the playbackState set to MPMusicPlaybackStatePaused.
Pressing pause in my car (or any remote access) generates the same conditions making it difficult to correctly detect the difference.
It would be nice if they added a notification that playback was done (similar to the other players).
Any suggestions?