Media Player

RSS for tag

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

Media Player Documentation

Posts under Media Player tag

68 Posts
Sort by:
Post not yet marked as solved
0 Replies
273 Views
let time1cmt = CMTimeGetSeconds(playerOK.currentTime()) time1 = Double(time1cmt) let time2cmt = CMTimeGetSeconds(playerOK.currentTime()) time2 = Double(time2cmt) videoDif = (time2 - time1) Now I'm using .currentTime() to get the start point and end point, but they don't seem to be accurate, is there any other way to get the time more accurately?
Posted
by
Post not yet marked as solved
1 Replies
411 Views
I am playing a video with AVPlayer, how can I get the float value of the FPS of the video? I readed it's possible with AVAssetTrack but I don't know how to implement it. On Swift/SwiftUI Thanks!
Posted
by
Post not yet marked as solved
0 Replies
299 Views
I'm using AVPlayer for playing m3u8. I want to get more control over the download audio chunks - redownload chunk after a failed operation. If some chunks are unavailable, the player will still play without returning an error. Can you advise me on some articles, maybe examples?
Posted
by
Post not yet marked as solved
0 Replies
372 Views
Im using more easily to create a pick up and play a video, and that part works, and to show the video I use this line: PhotoPickerResultView(result: photoPickerService.results[0]) and this part work fine to, arrives from this: struct PhotoPickerResultView: View {       var result: PHPickerResult       enum MediaType {     case loading, error, video   }       @State private var loaded = false   @State private var url: URL?   @State private var mediaType: MediaType = .loading   @State private var latestErrorDescription = ""       var body: some View {           Group {       switch mediaType {       case .loading:         ProgressView()       case .error:         VStack {           Image(systemName: "exclamationmark.triangle.fill")           Text(latestErrorDescription).font(.caption)         }         .foregroundColor(.gray)       case .video:         if url != nil {                                 VideoPlayer(player: AVPlayer(url: url!))          ... ..... My question is, How can I use or implement the custom buttons of the AVPlayer? like: @State private var player1 = AVPlayer(url: URL(string: "https...mp4")!)          VideoPlayer(player: player1)                   Button {           player1.play()         } label: {           Text(" PLAY ")         }         Button {           player1.pause()         } label: {           Text(" PAUSE ")         } from this line: PhotoPickerResultView(result: photoPickerService.results[0]) ??? or what do I have to change to use more easily that custom buttons of the AVPlayer?? Thanks
Posted
by
Post not yet marked as solved
2 Replies
609 Views
Hello, I'm using systemMusicPlayer to play Apple Music Live Radio Station got from Apple Music API. But it doesn't work. How can I do that? Error: Test[46751:13235249] [SDKPlayback] Failed to prepareToPlay error: Error Domain=MPMusicPlayerControllerErrorDomain Code=6 "Failed to prepare to play" UserInfo={NSDebugDescription=Failed to prepare to play} My implementation:    let musicPlayerController = MPMusicPlayerController.systemMusicPlayer musicPlayerController.beginGeneratingPlaybackNotifications()      musicPlayerController.setQueue(with: "ra.978194965")     musicPlayerController.play() API response: { “id”: “ra.978194965”, “type”: “stations”, “href”: “/v1/catalog/us/stations/ra.978194965”, “attributes”: { “artwork”: { “width”: 4320, “url”: “https://is2-ssl.mzstatic.com/image/thumb/Features114/v4/e5/10/76/e5107683-9e51-ebc5-3901-d8fbd65f2c2a/source/{w}x{h}sr.jpeg”, “height”: 1080, “textColor3”: “332628”, “textColor2”: “120509”, “textColor4”: “33272a”, “textColor1”: “000000”, “bgColor”: “f4f4f4”, “hasP3”: false }, “url”: “https://music.apple.com/us/station/apple-music-1/ra.978194965”, “mediaKind”: “audio”, “supportedDrms”: [ “fairplay”, “playready”, “widevine” ], “requiresSubscription”: false, “name”: “Apple Music 1”, “kind”: “streaming”, “radioUrl”: “itsradio://music.apple.com/us/station/ra.978194965”, “playParams”: { “id”: “ra.978194965”, “kind”: “radioStation”, “format”: “stream”, “stationHash”: “CgkIBRoFlaS40gMQBA”, “mediaType”: 0 }, “editorialNotes”: { “name”: “Apple Music 1”, “short”: “The new music that matters.”, “tagline”: “The new music that matters.” }, “isLive”: true } },``` Thank you! Best regards, MichaelNg
Posted
by
Post not yet marked as solved
7 Replies
642 Views
Hello, I'm the developer of an Apple Music app called Soor, I've been recently working on adding Catalyst support to the app. However, I've noticed some severe bugs while setting the queue for playing non-library items on macOS 12.2. Both MPMusicPlayerPlayParametersQueueDescriptor and MPMusicPlayerStoreQueueDescriptor fail to play items using valid playbackStore identifiers. The console logs the following errors: [SDKPlayback] systemMusicPlayer _establishConnectionIfNeeded timeout [ping did not pong] `[SDKPlayback] Failed to prepareToPlay error: Error Domain=NSOSStatusErrorDomain Code=9205 "(null)"` I have filed radars for this along with sample projects showcasing the issue. FB9890270 and FB9890331. Here's a gist of the sample code for which the player either completely fails to set the queue or now playing item stays nil. /// These are valid playback store ids retrieved from Apple Music API. /// You may replace them with any valid playback store IDs of your choice. let playbackStoreIDs = ["1588418743", "1604815955", "1596475453", "1562346959", "1596475469", "1596475460", "1580955750", "1591442362", "1607324602", "1531596345"] var playParams = [MPMusicPlayerPlayParameters]() for playbackStoreID in playbackStoreIDs { let param = MPMusicPlayerPlayParameters(dictionary: ["id": playbackStoreID, "kind": "song"])! playParams.append(param) } let queueDesc = MPMusicPlayerPlayParametersQueueDescriptor(playParametersQueue: playParams) queueDesc.startItemPlayParameters = playParams[3] player.setQueue(with: queueDesc) player.play() Has anyone managed to playback music correctly using only playback store ids on Catalyst?
Posted
by
Post not yet marked as solved
0 Replies
372 Views
So I am trying to add two buttons to the view of my SwiftUI app that will allow a user to fast forward and rewind the audio clip. I already have it working on the Lock Screen and notification bar, but in the app I can't figure out how to link two buttons to these actions. I am wondering if anyone is able to assist. In the MusicCore.swift I have the following func setupRemoteTransportControls() { // Get the shared MPRemoteCommandCenter let commandCenter = MPRemoteCommandCenter.shared() let changePlaybackPositionCommand = commandCenter.changePlaybackPositionCommand changePlaybackPositionCommand.isEnabled = true changePlaybackPositionCommand.addTarget { event in let seconds = (event as? MPChangePlaybackPositionCommandEvent)?.positionTime ?? 0 let time = CMTime(seconds: seconds, preferredTimescale: 1) self.player?.seek(to: time) return .success } let skipBackwardCommand = commandCenter.skipBackwardCommand if(MusicPlayer.mediatype == "podcast") { skipBackwardCommand.isEnabled = true skipBackwardCommand.preferredIntervals = [NSNumber(value: 10)] skipBackwardCommand.addTarget(handler: skipBackward) } else{ skipBackwardCommand.isEnabled = false } let skipForwardCommand = commandCenter.skipForwardCommand if(MusicPlayer.mediatype == "podcast") { skipForwardCommand.isEnabled = true skipForwardCommand.preferredIntervals = [NSNumber(value: 30)] } else{ skipForwardCommand.isEnabled = false } skipForwardCommand.addTarget(handler: skipForward) // Add handler for Play Command commandCenter.playCommand.addTarget { [unowned self] event in if self.player?.rate == 0.0 { self.player?.play() return .success } return .commandFailed } // Add handler for Pause Command commandCenter.pauseCommand.addTarget { [unowned self] event in if self.player?.rate == 1.0 { self.player?.pause() MPNowPlayingInfoCenter.default().nowPlayingInfo?[MPNowPlayingInfoPropertyElapsedPlaybackTime] = Int(Double((self.player?.currentTime().seconds)!)) return .success } return .commandFailed } func skipBackward(_ event: MPRemoteCommandEvent) -> MPRemoteCommandHandlerStatus { //self.player?.seek(to: CMTimeMakeWithSeconds(CMTimeGetSeconds((self.player?.currentTime())!).advanced(by: -30), preferredTimescale: 1)) // print(CMTimeGetSeconds((self.player?.currentTime())!)) //Output: 42 //print(event.interval) //self.player!.seek(to: CMTimeMakeWithSeconds(CMTimeGetSeconds((self.player?.currentTime())!).advanced(by: -30), preferredTimescale: 1)) let currentTime = self.player?.currentTime() self.player?.seek(to: CMTime(seconds: currentTime!.seconds - 10, preferredTimescale: 1), completionHandler: { isCompleted in if isCompleted { MPNowPlayingInfoCenter.default().nowPlayingInfo?[MPNowPlayingInfoPropertyElapsedPlaybackTime] = Int(Double((self.player?.currentTime().seconds)!)) } }) return .success } func skipForward(_ event: MPRemoteCommandEvent) -> MPRemoteCommandHandlerStatus { //self.player?.seek(to: CMTimeMakeWithSeconds(CMTimeGetSeconds((self.player?.currentTime())!).advanced(by: 30), preferredTimescale: 1)) let currentTime = self.player?.currentTime() self.player?.seek(to: CMTime(seconds: currentTime!.seconds + 30, preferredTimescale: 1), completionHandler: { isCompleted in if isCompleted { MPNowPlayingInfoCenter.default().nowPlayingInfo?[MPNowPlayingInfoPropertyElapsedPlaybackTime] = Int(Double((self.player?.currentTime().seconds)!)) } }) return .success } } But how can I call that from inside a View?
Posted
by
Post not yet marked as solved
0 Replies
332 Views
Hi, We have a Video Player App, which seem to crash randomly when player is closed. Crash Info: crash_info_entry_0 : BUG IN CLIENT OF LIBDISPATCH: dispatch_sync called on queue already owned by current thread Stack trace: 0 libdispatch.dylib 0x12dd0 __DISPATCH_WAIT_FOR_QUEUE__ + 484 1 libdispatch.dylib 0x12900 _dispatch_sync_f_slow + 144 2 MediaToolbox 0x1f6374 FigCaptionRendererSessionSetPlayer + 68 3 MediaToolbox 0x2a7b30 setPlayerDo + 184 4 libdispatch.dylib 0x3950 _dispatch_client_callout + 20 5 libdispatch.dylib 0x12a70 _dispatch_lane_barrier_sync_invoke_and_complete + 56 6 MediaToolbox 0x2a7a6c -[FigSubtitleCALayer setPlayer:] + 64 7 AVFCore 0x6e2c0 -[AVPlayer _removeLayer:videoLayer:closedCaptionLayer:subtitleLayer:interstitialLayer:] + 572 8 AVFCore 0x30dc8 -[AVPlayerLayer dealloc] + 324 9 Foundation 0x2cf78 NSKVODeallocate + 216 10 QuartzCore 0x68c54 CA::Layer::free_transaction(CA::Transaction*) + 404 11 QuartzCore 0x4f284 CA::Transaction::commit() + 952 12 MediaToolbox 0x3375bc setBounds + 376 13 MediaToolbox 0x200160 UpdateLayoutContext + 892 14 MediaToolbox 0x1feda8 onCaptionInputDo + 212 15 libdispatch.dylib 0x3950 _dispatch_client_callout + 20 16 libdispatch.dylib 0xb0ac _dispatch_lane_serial_drain + 664 17 libdispatch.dylib 0xbc10 _dispatch_lane_invoke + 392 18 libdispatch.dylib 0x16318 _dispatch_workloop_worker_thread + 656 19 libsystem_pthread.dylib 0x11b0 _pthread_wqthread + 288 20 libsystem_pthread.dylib 0xf50 start_wqthread + 8
Posted
by
Post not yet marked as solved
0 Replies
214 Views
Attempting to pull a podcast, via it's ID, leads to a CORS error, as it has the response header: access-control-allow-origin: http://localhost:3000 Meaning, locally, I am able to pull the required podcast episode list, but as soon as I am in staging or production, the whole thing falls over. Has anyone come across this issue, and does anyone have any work arounds?
Posted
by
Post not yet marked as solved
0 Replies
319 Views
I have a MUSIC website that uses the BetterAudioPlaylist front-end HTML5 player (https://github.com/NelsWebDev/BetterAudioPlaylist). For over 2 years it has worked flawlessly on my iPhone, however when I updated to iOS 12.1 it no longer advances to the next audio file if the screen is locked. I have tried going into Safari settings and used my troubleshooting skills to verify it has nothing to do with my settings. Is this Apple pushing out the little guy in favor of iTunes? Has anyone else had this problem? I contacted Apple's Developers support email, however they never responded. Please help!
Posted
by
Post not yet marked as solved
0 Replies
240 Views
EarPods toggle button event has been received on iPhone 7. But it hasn't happened since yesterday. The source code has never been changed. The source code is roughly like this. [[UIApplication sharedApplication] beginReceivingRemoteControlEvents]; MPRemoteCommandCenter *commandCenter = [MPRemoteCommandCenter sharedCommandCenter]; [commandCenter.togglePlayPauseCommand addTarget:self action:@selector(onTogglePlayPause:)]; commandCenter.togglePlayPauseCommand.enabled = 1; - (MPRemoteCommandHandlerStatus)onTogglePlayPause:(MPRemoteCommandHandlerStatus*)event { NSLog(@"toggle event! - never called...."); return MPRemoteCommandHandlerStatusSuccess; } env iphone 7 (ios 15.2) xcode 13.1 How do I get this event?
Posted
by
Post not yet marked as solved
0 Replies
281 Views
I am able to play AES encrypted content in online mode and download it . But the downloaded content does not play in offline mode. Steps: Get encrypted content url call backend api to get token to decrypt the url play the content . works download content. works off the internet and try to play . Fails to play.
Posted
by
Post not yet marked as solved
0 Replies
197 Views
When the player's rate is being set to a different value than 1.0 I am experiencing after a few seconds issues with handling different remote commands. In my case when I change the rate e.g. to 3.0 after a little time only remoteCenter.playCommand's handle is triggered. Even when the player still plays. The handlers return .success after the block content is successfully executed. All relevant commands are enabled (command.isEnabled). The properties of MPRemoteCommandCenter are pretty simple so there is a little space to adjust it. I have tried to toggle the isEnabled value on different commands. Explicitly called unregisterForRemoteNotifications, registerForRemoteNotifications on UIApplication Tested the case only with the playCommand, and pauseCommand. Used the older API with selectors Nothing of this has helped. let remoteCenter = MPRemoteCommandCenter.shared() remoteCenter.playCommand.addTarget { [weak self] _ in ...
Posted
by
Post not yet marked as solved
0 Replies
147 Views
When I try to play music through my built in speakers it automatically goes through my TV, I don't want it to so I tried going through Sounds and changing the settings but I can't stop it doing it, any ideas please?
Posted
by