Media Player

RSS for tag

Find and play songs, audio podcasts, audio books, and more from within your app using Media Player.

Posts under Media Player tag

85 Posts
Sort by:

Post

Replies

Boosts

Views

Activity

HLS Playback Issue with Discontinuity Tag and Low Bitrate Streams and Seek on iOS 17
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.
0
0
82
1w
Audio transition using MPMusicPlayerApplicationController
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
0
0
144
1w
MPRemoteCommandCenter stops UIKeyCommand from working for a few seconds
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!
0
0
84
1w
Get downloaded tracks when querying MPMediaItem and can't detect them
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
0
0
119
2w
Outputvolume of AVAudioSession returning rounded values
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
1
0
347
3w
How to detect the end of playback with the system music player?
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?
0
0
277
May โ€™24
How to addObserver for currentPlaybackTime for the system music player?
I'm using the systemMusicPlayer to play music and want to update the playback time using addObserver forKeyPath. [self setMusicPlayer: [MPMusicPlayerController systemMusicPlayer]]; I've tried these two methods: [self addObserver:self forKeyPath:@"musicPlayer.currentPlaybackTime" options:NSKeyValueObservingOptionNew | NSKeyValueObservingOptionInitial context:&musicPlayer]; [self.musicPlayer addObserver:self forKeyPath:@"currentPlaybackTime" options:NSKeyValueObservingOptionNew | NSKeyValueObservingOptionInitial context:&musicPlayer]; I do get the initial values for currentPlaybackTime in: -(void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context but I never get any calls when the player is playing the song (the whole point). If I set the currentPlaybackTime to a specific value (locating manually using a slider), I get calls with the values I set (useless since I know what I am setting them to). How are we supposed to track the playback time without just polling it constantly?
1
0
301
May โ€™24
AVPlayer CoreMediaErrorDomain -12642
Hi everyone, I am having a problem on AVPlayer when I try to play some videos. The video starts for a few seconds, but immediately after I see a black screen and in the console there is the following error: <__NSArrayM 0x14dbf9f30>( { StreamPlaylistError = "-12314"; comment = "have audio audio-aacl-54 in STREAMINF without EXT-X-MEDIA audio group"; date = "2024-05-13 20:46:19 +0000"; domain = CoreMediaErrorDomain; status = "-12642"; uri = "http://127.0.0.1:8080/master.m3u8"; }, { "c-conn-type" = 1; "c-severity" = 2; comment = "Playlist parse error"; "cs-guid" = "871C1871-D566-4A3A-8465-2C58FDC18A19"; date = "2024-05-13 20:46:19 +0000"; domain = CoreMediaErrorDomain; status = "-12642"; uri = "http://127.0.0.1:8080/master.m3u8"; } )
1
0
415
May โ€™24
HDR10 MVHECV can not play on Safari
Hi, just generated a HDR10 MVHEVC file, mediainfo is below: Color range : Limited Color primaries : BT.2020 Transfer characteristics : PQ Matrix coefficients : BT.2020 non-constant Codec configuration box : hvcC+lhvC then generate the segment files with below command: mediafilesegmenter --iso-fragmented -t 4 -f av_1 av_new_1.mov then upload the segment files and prog_index.m3u8 to web server. just find that can not play the HLS stream on Safari... the url is http://ip/vod/prog_index.m3u8 just checked that if i remove the tag Transfer characteristics : PQ when generating the MVHEVC file. above same mediafilesegmenter command and upload the files to web server. the new version of HLS stream is can play on Safari... Is there any way to play HLS PQ video on Safari. thanks.
0
0
288
May โ€™24
"Remote call timed out" error when trying to play large collection of music items with MusicKit's ApplicationMusicPlayer
I am using MusicKit ApplicationMusicPlayer to play music in my app. Everything works fine as long as I'm not playing large playlists that contain hundreds of songs. When I to play collection of songs that is larger than around 300 I'm always getting the error message saying: "Prepare to play failed" UserInfo={NSDebugDescription=Prepare to play failed, NSUnderlyingError=0x121d42dc0 {Error Domain=MPMusicPlayerControllerErrorDomain Code=9 "Remote call timed out" UserInfo={NSDebugDescription=Remote call timed out}}})) It doesn't matter if songs are downloaded to the device or not. I am aware that there is another initializer for player's queue that accepts Playlist instances but in my app users can choose to sort playlist tracks in different order than the default and that makes using that initializer not feasible for me. I tried everything I could think of, I tried to fall back on MPMusicPlayerController and pass array of MPMusicPlayerPlayParameters to it but the result was the same. typealias QueueEntry = ApplicationMusicPlayer.Queue.Entry let player = ApplicationMusicPlayer.shared let entries: [QueueEntry] = tracks .compactMap { guard let song = $0 as? Song else { return nil } return QueueEntry(song) } Task(priority: .high) { [player] in do { player.queue = .init(entries, startingAt: nil) try await player.play() // prepareToPlay failed } catch { print(error) } }
0
0
295
Apr โ€™24
how mediafilesegmenter generat AES-128 HLS?
I am using below commad line to generate AES-128 HLS, mediafilesegmenter -iso-fragmented --encrypt-key-file=my.key -S -f /Volumes/Samsung/pattern/vision_pro/hls/*** /Volumes/Samsung/pattern/vision_pro/***.mov but it always generates SAMPLE-AES, even I removed -S #EXT-X-KEY:METHOD=SAMPLE-AES,URI="enc.key",IV=0x7316166d6a85f56f3d4606eaebc3aa44 How I can generate AES-128 HLS? Thanks.
0
0
282
Apr โ€™24
Avplayer showing black screen while playing on iOS 17.3.1 with low probability
Some users of our app get a black screen when playing mp4 files on their phones. The users are all running iOS 17.3.1 and cannot catch the error message when playing a black screen. The user can play the video normally after restarting the mobile phone. However, we want to solve this problem from the code. We use two Avplayers to complete the sequential playback of multiple videos. override init(frame: CGRect) { super.init(frame: frame) layer.addSublayer(videoPlayerA) layer.addSublayer(videoPlayerB) } lazy var layers = [videoPlayerA, videoPlayerB] lazy var videoPlayerA: AVPlayerLayer = { let avPlayerLayer = AVPlayerLayer(player: AVPlayer()) avPlayerLayer.contentsScale = UIScreen.main.scale avPlayerLayer.videoGravity = .resizeAspectFill return avPlayerLayer }() lazy var videoPlayerB: AVPlayerLayer = { let avPlayerLayer = AVPlayerLayer(player: AVPlayer()) avPlayerLayer.contentsScale = UIScreen.main.scale avPlayerLayer.videoGravity = .resizeAspectFill return avPlayerLayer }() func play() { if let path = paths[safe: currentIndex] { currentVideoPath = path currentPlayer = AVPlayer(playerItem: AVPlayerItem(url: URL(fileURLWithPath: path))) layers.first?.player?.pause() layer.insertSublayer(layers.first ?? AVPlayerLayer(), below: layers.last) layers.swapAt(0, 1) layers.first?.player = currentPlayer layers.first?.player?.play() SHPlayerGlobalStatus.sharedInstance.isLocalPlayerPlaying = true try? AVAudioSession.sharedInstance().setCategory(.playback) try? AVAudioSession.sharedInstance().setActive(true) }
0
0
315
Apr โ€™24
How to display artwork images from MusicKit with UIKit?
In SwiftUI there is a built-in component for displaying album artworks called Artwork but there is no equivalent for UIKit. My current approach is to use the .url() method to read image's URL and download the image or read it from the disk but the performance is much worse than it was previously with MPMediaItem's artworkImage method. let artworkQueue = DispatchQueue( label: "MusicKit-ArtworkQueue", qos: .default, attributes: .concurrent ) let artworkSemaphore = DispatchSemaphore(value: 5) extension Song { func artworkImage(for size: CGSize, completion: @escaping (UIImage?) -> Void) { artworkQueue.async { artworkSemaphore.wait() defer { artworkSemaphore.signal() } let imageURL = artwork?.url( width: Int(size.width), height: Int(size.height) ) // I hate doing this as it might very well break in the future guard let imageURL, imageURL.scheme == "musicKit" else { return completion(nil) } guard let imageData = try? Data(contentsOf: imageURL), let image = UIImage(data: imageData) else { return completion(nil) } completion(image) } } } I really dislike this approach because it feels hacky but somewhat works. You might ask what's the semaphore for? Well, without it I could notice that MusicKit was choking and after reading too many artworks at once. Can someone from Apple please provide us with an example on how to use MusicKit with UIKit properly? Ideally (IMO) we would have a method defined on Song and other MusicKit structures that returns the image for us, just like MPMediaItem had the .artwork() method. It would make our lives so much easier.
1
0
376
Apr โ€™24
CPGridTemplate/ CPListImageRowItem support on iOS13
I want to create a CPListImageRowItem/CPGridTemplate for the audio app which supports from iOS 13. for iOS14 and above I can able to do that with CPGridTemplate/ CPListImageRowItem but in iOS 13 how can we do? Because to support audio app from iOS13 I am using MPPlayableContentManager. So, are we able to achieve it iOS 13? Grid Should look like below image Please Suggest any way to achieve this kind of design? Thanks in advance.
1
0
398
Apr โ€™24
Creating a song using MediaPlayer so it shows up in a playlist, from stored file on device.
I'm trying to accomplish creating a new playlist on device that appears in AppleMusic, and adding into the playlist a selection of MP3s within a small IOS app. Now the MP3's are either a stream of bytes, or a flat file already stored on the device (the app itself generates these - they aren't downloaded, they are created in app, and then stored on the local device) in it's local storage space. The idea is that created tracks can show up in a specific play list on the device. Now, there appears to be some conflict as to what framework I need to use. I've found MPMediaPlayer, which appears to allow me to create a playlist using the GetPlaylist call, although the documentation on this seems pretty sparse and there's not a lot of examples I can find on how to use this? It looks like a UUID is passed in, but there is no documentation on what this UUID is or where it comes from? If I want to create a new Playlist, I presume I need to generate a UUID, and then store that locally in order to be able to access that playlist again later, yes? There's an AddItem call which looks like it's how you add a track to a playlist, but there's no documentation on how you generate an entry. The documentation for this function talks about a Product ID, without describing what the product ID is, or where it needs to come from. Is this a GUID? Is it a name/description? Does it have to be unique? I'm assuming this Product ID refers to that which is being added to the playlist, but the documentation is sadly lacking in terms of explaining what the product ID refers to. Is it a media Item, or is that what is created when whatever entity the Product ID is referring to is added to the playlist? I'm assuming I can create a NSURL of the file that is stored that is actually the MP3 sample, but what I do with that in order to actually add it as a playlist entry is unknown. I'm sure there is a mechanism to do this, it's just not clear what that is. There's a lack of understanding or explanation of what the process is here, and some illumination would be helpful.
1
0
380
Mar โ€™24
Building a music application using an API
Hello everyone, my name is Joshua Osagie. For 2 months now, I have been trying to build my own music application, but unfortunately, I canโ€™t because I was thinking I would get an API from maybe Apple Music or Spotify that will grant me access to over 100 million music. Even if the API is paid for, I have been doing my research, but then it's kind of impossible. So please, if anyone has an idea on what I can do to bring this application to life, I will really appreciate it. Or if anyone could share me an idea on how to get over millions of music on my app, I will be really grateful.
0
0
380
Mar โ€™24