I would like to update current song name into this picture. I don't know how to call that one and need to show image. I am using AVPlayer now. I would like to know how to do.
I have tried this but it show error.
Undefined symbols for architecture armv7s:"_MPMediaItemPropertyTitle", referenced from: -[PlayViewController playPressed] in PlayViewController.o
MPNowPlayingInfoCenter *infoCenter = [MPNowPlayingInfoCenter defaultCenter];
infoCenter.nowPlayingInfo =
[NSDictionary dictionaryWithObjectsAndKeys:#"my title", MPMediaItemPropertyTitle,
#"my artist", MPMediaItemPropertyArtist,
nil];
Did you #import <MediaPlayer/MediaPlayer.h> in this class?
Is the MediaPlayer framework linked to your project?
Related
I am loading my iPod library into AVQueuePlayer and playing it using this:
[[AVQueuePlayer alloc]]initWithItems:[MPMediaCollectionInstance items] ]; //just one line.
But how do I read which MPMediaItem is currently playing? I want to know information like artist / song name etc.
Thanks.
Have the instance of the AVQueuePlayer that you have allocated.
AVQueuePlayer *_queuePlayer = [[AVQueuePlayer alloc] initWithItems:[MPMediaCollectionInstance items]];
With that instance, you can get the AVPlayerItem.
AVPlayerItem *currentItem = _queuePlayer.currentItem;
For the above line, please check the doc reference.
And now try the following code
NSArray *metadataList = [currentItem.asset commonMetadata];
for (AVMetadataItem *metaItem in metadataList) {
NSLog(#"%#",[metaItem commonKey]);
}
Which will give a list as follows:
title
creationDate
artwork
albumName
artist
Now you can get the value for corresponding keys. For this, you have to refer this doc too.
I've seen some demos where UIPopoverController is used and would like to use it in my apps.
So does anyone have any good tutorials that you could link me?
Is it possible to use it in relation to UISegmentedControl where different popover windows are summoned when different segments are selected as a type of a switch view function?
Here are some tutorials:
iPad for iPhone Developers 101: UIPopoverController Tutorial
[iPad App Video] iPad App Tutorial – UIPopoverController
Segmented Popover:
Using a UISegmentedControl in the footer of UIPopoverController
Buttons inside of a Pop Over Controller on the iPad, no UISegmentUISegmentedControl used but looks like one
For popover in iPad we can use ActionSheetStringPicker, and for implementing it in your project you need to import ActionSheetStringPicker into your controller.
like - #imaport "ActionSheetStringPicker.h"
After importing this you have to create an array which has only string type value.
e.g.
NSArray *sourceArray=[[NSArray alloc]initWithObjects:#"Take Photo",#"Choose Photo", nil];
And last you have to implement below method.
[ActionSheetStringPicker showPickerWithTitle:#"Any title"
rows:sourceArray
initialSelection:yourInitialSelectionIntValue
doneBlock:^(ActionSheetStringPicker *picker, NSInteger selectedIndex, id selectedValue) {
NSLog(#" Index : %ld, value : %#",
(long)selectedIndex, selectedValue);
if ([selectedValue isEqualToString:#"Choose Photo"]) {
// open photo lib
[self youerMethdeOpenPhotoLib];
}
else
{
// open Camera
[self yourMethodOpenCamera];
}
}
cancelBlock:^(ActionSheetStringPicker *picker) {
NSLog(#"Select photo Cancel");
}origin:YourTapButtonObject];
I would like to handle the paste event in my UIViewController for my attached UITextView, so that if the pasted data is text or html it should paste the data in as normal and as it already does, but if it is something else like a image or pdf or anything, I would like to store the data locally in another way and not paste it into the UITextView (as it can not do this).
How would I go around doing this? In the only example I can find from Apple, they know the type of the data they paste. Even getting my "-(void)paste:(id)sender" method in my controller to get called when there is a paste event in my UITextView escapes me.
Thank you
You can use the method canReadObjectForClasses:options: to test for something without actually retrieving the value.
For example, testing for strings:
NSArray *classes = [NSArray arrayWithObject:[NSString class]];
NSDictionary *options = [NSDictionary dictionary];
if ([[NSPasteboard generalPasteboard] canReadObjectForClasses:classes options:options]) {
NSLog(#"yup, there is a string in here");
}
Update:
You're checking for all objects in the paste board this way, just add any class that you expect on the array.
NSArray *classes = [NSArray arrayWithObjects:[NSURL class], [NSString class], nil];
Use the UIResponderStandardEditActions protocol to implement the paste method.
I want to play particular selected song from my ipod music library.How can i do that?
My idea is to save the title name from MPMediaQuery and then play later on when app starts
so any one can have idea to do this?
Thank You.
The basic solution is to save the unique identifier each song in the library has, aka MPMediaItemPropertyPersistentID. You can use this ID to play the song, and you can save the ID to memory in order to remember the song the user selected between launches. If you don't know how the Media Player Framework works, look at the AddMusic sample code.
Your view controller must implement the MPMediaPickerControllerDelegate protocol. Assuming you're just allowing the user to select a single song, then the basic outline of your callback will look something like this.
- (void)mediaPicker:(MPMediaPickerController *)mediaPicker didPickMediaItems:(MPMediaItemCollection *)mediaItemCollection
{
NSArray* items = [mediaItemCollection items];
if ([items count] == 1)
{
MPMediaItem* song = (MPMediaItem *)[items objectAtIndex:0];
NSNumber* persistentId = [song valueForProperty:MPMediaItemPropertyPersistentID];
// ...Save/Play here...
}
}
At this point you can use the persistent ID to play the song, and/or save it to user defaults.
Just looking for how to programmatically add a watermark or some sort of overlay to video using cocoa. Not looking for a step by step ( although that would awesome ), but more or less looking for where I should start looking to learn how. Are there frameworks developed to work for this. Would like something native to cocoa or objective-c or c because I would like to eventually give this a go on the iPhone. Any help would be great.
I'm not sure if you mean just for playback, or if you'd like to export a video with a watermark that'll show up on other players.
If you mean just for playback, you can probably just add a view on top of the player view on Mac and iPhone that contains the watermark.
If you'd like a watermark on the video itself, this is hard on the Mac and probably impossible on the iPhone without essentially rewriting QuickTime.
On the Mac, the code might look like this (you need to import QTKit):
// Make a new movie so we don't destroy the existing one
QTMovie* movie = [[QTMovie alloc] initWithMovie:currentMovie
timeRange:QTMakeTimeRange(QTMakeTime(0,1000), [currentMovie duration])
error:nil];
// Make it editable
[movie setAttribute:[NSNumber numberWithBool:YES]
forKey:QTMovieEditableAttribute];
//Get the size
NSValue *value = [movie attributeForKey:QTMovieNaturalSizeAttribute];
NSSize size = [value sizeValue];
// Add a new track to the movie and make it the frontmost layer
QTTrack *track = [movie addVideoTrackWithSize:size];
[track setAttribute:[NSNumber numberWithShort:-1] forKey:QTTrackLayerAttribute];
// Create a codec dictionary for the image we're about to add
NSDictionary *imageDict = [NSDictionary dictionaryWithObjectsAndKeys:
#"tiff", QTAddImageCodecType,
[NSNumber numberWithLong:codecHighQuality], QTAddImageCodecQuality, nil];
// Get the video length in QT speak
QTTime qttime = [currentMovie duration];
NSTimeInterval reftime;
QTGetTimeInterval(qttime, &reftime);
//Add the image for the entire duration of the video
[track addImage:image forDuration:qttime withAttributes:imageDict];
// Finally, tell the track that it should use its alpha correctly
MediaHandler media = GetMediaHandler([[track media] quickTimeMedia]);
MediaSetGraphicsMode(media, graphicsModeStraightAlpha, NULL);
... And that's it! Your movie now has a watermark, and you can export it to file.