HomeiOS Developmentios - MPMusicPlayerController.applicationQueuePlayer not updating begin and finish occasions utilizing MPMusicPlayerMediaItemQueueDescriptor

ios – MPMusicPlayerController.applicationQueuePlayer not updating begin and finish occasions utilizing MPMusicPlayerMediaItemQueueDescriptor


I am experiencing a problem with the MPMusicPlayerController.applicationQueuePlayer when setting the queue utilizing an MPMusicPlayerMediaItemQueueDescriptor with particular begin and finish occasions. As an alternative of updating to the brand new begin and finish occasions, the applicationQueuePlayer reverts to its final identified configuration for the beforehand used MPMediaItem.

Implementation particulars:

Customers decide songs from their Apple Music library. Within the code, the tune is about to the MPMusicPlayerController.applicationQueuePlayer utilizing the MPMusicPlayerMediaItemQueueDescriptor.
The beginning and finish occasions are set instantly.
Nonetheless, for the reason that replace to model 16.4, setting the beginning and finish occasions utilizing MPMusicPlayerMediaItemQueueDescriptor appears to be damaged in the event you set it to a beforehand set MediaItem. After passing the TimeInterval, the beginning and finish occasions seem as “unknown” the second time.

Instance:

Person chooses a tune.
App units the tune to the queue participant with a begin time of 30 seconds and finish time of 60 seconds.
Person performs that phase of the tune (works accurately).
Tune ends, cease is known as on the applicationQueuePlayer (ought to clear the queue).
Person modifications the beginning phase of the tune to twenty seconds.
App units the tune to the queue participant with a begin time of 20 seconds and finish time of 60 seconds.
Person hits play, however step #2 performs as a substitute.
Steps to breed:

Create a static reference to the applicationQueuePlayer:
swift
Copy code

static var musicPlayer: MPMusicPlayerController = {
    MPMusicPlayerController.applicationQueuePlayer
}()

Seize a tune from the Apple Music Library containing a persistentId. Guarantee it is added to your Apple Music Library and downloaded to the gadget.
Within the mediaPicker delegate callback, assign the MPMediaItem retrieved to an area variable.
Use the next perform to create a descriptor:

static func descriptor(fromMediaItem mediaItem: MPMediaItem,
                       startTime: TimeInterval,
                       endTime: TimeInterval) -> MPMusicPlayerMediaItemQueueDescriptor {
    let mediaCollection = MPMediaItemCollection(objects: [mediaItem])
    let descriptor = MPMusicPlayerMediaItemQueueDescriptor(itemCollection: mediaCollection)
    descriptor.setStartTime(startTime, for: mediaItem)
    descriptor.setEndTime(endTime, for: mediaItem)
    descriptor.startItem = mediaItem
    return descriptor
}

Set the descriptor to your applicationQueuePlayer utilizing setQueue(with: descriptor).

Is there a identified workaround or answer for this concern?

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments