Get album artwork from song playing through Apple Music - ios

I am testing my app with Apple Music, my app grabs the current playing song and displays relevant information on it.
One of the steps is to get the album artwork, however I find that when the song is playing from Apple Music it does not contain any artwork.
Here is my code, the first if condition is ran, which suggests that the artwork is initialized, however I get no image.
Does anyone know how I can get the artwork when the song is being played though Apple Music?
song is of type MPMediaItem
CGSize artworkImageViewSize = cell.albumImage.bounds.size;
MPMediaItemArtwork *artwork = [song valueForProperty:MPMediaItemPropertyArtwork];
if (artwork)
{
cell.albumImage.image = [artwork imageWithSize:artworkImageViewSize];
}
else
{
cell.albumImage.image = [UIImage imageNamed:#"noArtwork"];
}
Whenever I try to print artwork.bounds I get back null.

Related

Inserting slowMo AVComposition into AVMutableComposition

PHPhotoLibrary gives an AVComposition rather than an AVURLAsset for a video recorded in SlowMo. I want to insert slowMo videos into another AVMutableComposition, so this means I need to insert this AVComposition into AVMutableComposition which is my editing timeline. The hack I used before was to load the tracks and segments and find the mediaURL of asset.
AVCompositionTrack *track = [avAsset tracks][0];
AVCompositionTrackSegment *segment = track.segments[0];
mediaURL = [segment sourceURL];
Once I had mediaURL, I was able to create a new AVAsset that could be inserted into AVMutableComposition. But I wonder if there is a cleaner approach that allows the slowMo video composition to be directly inserted into the timeline AVMutableComposition?

iOS Swift UIImagePickerController Show Only Videos Whose Duration is Below a Specific Length

When presenting the UIImagePickerController to show mediaType kUTTypeMovie, how can I filter it so that it only shows videos that are under a specific duration?
You can filter video only using:
videoPicker.mediaTypes = [kUTTypeMovie as String]
But filtering video under specific duration is not possible.

UISlider and playing sound in iOS

I'm trying to use a UISlider to play sound in a fashion which emulates how a violin bow would play on a string. At current, I can get sound playing from the slider however the functionality isn't correct.
-(IBAction) slider
{
NSString* path = [[NSBundle mainBundle] pathForResource:#"im_on" ofType:#"mp3" ];
if (song) [song release];
song = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path] error:NULL];
[song play];
}
This is code and there is not much else to it. I have linked this method in IB to a slider which is triggered on the event Value Changed. When set to continuous = YES, when the slider begins to slide, the sound plays. However if it continues to slide the sound will stop until the slider stops where it then play again. When set to continuous = NO, the sound does not play when the value changes but when the touch is lifted. the sound continues to play while the value is hanging after that.
Is there a way to have the sound continue to play until the slider stops/changes direction/touch is released? i.e override all but the first value changed sent event until x condition is met.

How to reset the content URL for MPMoviePlayerController when playing a video?

I want to reset the content URL for the MPMoviePlayerController object when playing a video.
on a button click, I am setting the content URL like below,
[videoPlayer setContentURL:url];
But i am getting the "Bad Access" error.
Is there a way to change the url when a movie player is already playing a video?
It should stop the previous video and should start the video for the new url.
It means you didn't allocate memory to videoplayer
MPMoviePlayerController * videoplayer = [MPMoviePlayerController alloc] init];
[videoplayer setcontenturl: url];
it will not give you any error.

MPMediaItem with no artwork when bought from iTunes

I'm developing a iOS media Player using the iPodMusicPlayer. I have a UITableView with the MPMediaPickerController selector.
After buying a song from the iTunes store, the picked track has no artwork in the iPodMusicPlayer:
MPMediaPlayer* player = [MPMediaPlayer iPodMusicPlayer];
MPMediaItem*item = [player nowPlayingItem];
MPMediaItemArtwork *artwork = [item valueForProperty:MPMediaItemPropertyArtwork];
UIImage *albumCoverArt = [artwork imageWithSize:CGSizeMake(100.0f, 100.0f)];
if(albumCoverArt!=nil) {
// do something
}
else {
// nil before sync
}
After syncing with iTunes the song reveals the artwork.
Since before syncing, the iPod player shows the artwork, I think I'm missing something in the code when requesting the item to the MPMediaLibrary.
Any idea?
I am having the same issue.
Seems like when you buy a song from the iTunes store directly on your iPhone, retrieving the artwork will give you a blank image.
After syncing your phone with iTunes, solves it and then you will get the right image from MPMediaItemArtwork.
Offcourse I would suspect the right image immediately after buying from iTunes.

Resources