Hi all
I've create simple movie player in iPhone development. But i got just only vedio's voice.
Here is my code (when button click),
-(IBAction)playMe{
NSBundle *bundle=[NSBundle mainBundle];
NSString *moviePath=[bundle pathForResource:#"iiii" ofType:#"mp4"];
NSURL *movieURL = [NSURL fileURLWithPath:moviePath];
MPMoviePlayerController *theMovie=[[MPMoviePlayerController alloc] initWithContentURL:movieURL];
theMovie.scalingMode = MPMovieScalingModeAspectFill;
[theMovie play];
[self.view addSubview:theMovie.view];
}
When i click i got only voice not with movie. I also used iOS 4.1 simulator.
it may be because of you have not set frame to display movie player try this.
theMovie.view.frame=CGRectMake(0,0,300.400);
If this does not work
you can check out following tutorials
http://www.edumobile.org/iphone/iphone-programming-tutorials/how-to-play-video-in-iphoneos4/
http://iosdevelopertips.com/video/getting-mpmovieplayercontroller-to-cooperate-with-ios4-3-2-ipad-and-earlier-versions-of-iphone-sdk.html
http://www.devx.com/wireless/Article/44642/1954
http://iosdevelopertips.com/video/how-to-play-movies-from-application-bundle-or-from-a-remote-server-url.html
Related
I'm using the Standard Matchmaking User Interface and two iPads iOS6. The problem is when I create a new match in the first device, the second device supposed to see the existing match when I view the Matchmaking User Interface but it's not. I'm sure my code is correct. here is the method:
-(void)findMatchWithMinPlayers:(int)minPlayers maxPlayers:(int)maxPlayers viewController:(UIViewController*)viewController {
// the view that will present Matchmaker View Controller
self.viewCaller = viewController;
GKMatchRequest *request = [[GKMatchRequest alloc] init];
request.minPlayers = minPlayers;
request.maxPlayers = maxPlayers;
GKTurnBasedMatchmakerViewController *viewMatchmaker = [[GKTurnBasedMatchmakerViewController alloc] initWithMatchRequest:request];
viewMatchmaker.turnBasedMatchmakerDelegate = self;
viewMatchmaker.showExistingMatches = YES;
[self.viewCaller presentViewController:viewMatchmaker animated:YES completion:nil];
}
I even tried on two different sample games but the same problem, so how can I solve this ?
When Gamekit does matchmaker for a turnbase match it is trying to find a match with an open slot to fill the player in. If it cannot find an open slot to fill the player in it then creates a new match.
Try on one device to create a match and go through one turn with that device, that is when you call...
endTurnWithNextParticipants:turnTimeout:matchData:completionHandler:
Then on the other device try looking for a match.
I am currently trying to save video files to iCloud. I am using Core Data to save filename strings (filename.MOV) for each video, to then retrieve them from the ubiquity container. It all works locally (files save, and can be accessed from their URLs), but I am struggling to obtain the videos over iCloud. The Core Data syncs, so I have access to the file names, but when I try to obtain the video from the URL, I am unable to.
This is how I save the video after obtaining its url (videoURL below) from UIImagePicker, and creating a unique string from the current date:
NSString *videoFileName = [stringFromDate stringByAppendingPathExtension:#"MOV"];
NSURL *ubiquityContainer = [[NSFileManager defaultManager] URLForUbiquityContainerIdentifier:nil];
NSURL *saveToURL = [ubiquityContainer URLByAppendingPathComponent:videoFileName];
BOOL ok;
ok = [[NSFileManager defaultManager] setUbiquitous:YES itemAtURL:videoURL destinationURL:saveToURL error:nil];
if (!ok) NSLog(#"error saving");
I then have a Core Data table view to list all of the videos. Here I observe changes in the Core Data to sync with iCloud and reload (this all still works fine):
- (void)viewDidLoad {
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(reloadFetchedResults:)
name:#"SomethingChanged"
object:[[UIApplication sharedApplication] delegate]];
}
- (void)reloadFetchedResults:(NSNotification*)note {
[self performFetch];
}
At this point, I want the ubiquity container to update, so that when I choose a video, and segue to a view controller to watch it, the video file can be found. (self.video is my Core Data video entity) (asset is is the video asset, which I can play back)
NSURL *ubiquityContainer = [[NSFileManager defaultManager] URLForUbiquityContainerIdentifier:nil];
ubiquityContainer = [ubiquityContainer URLByAppendingPathComponent:self.video.url];
AVURLAsset *asset = [AVURLAsset URLAssetWithURL:ubiquityContainer options:[NSDictionary dictionaryWithObject:[NSNumber numberWithBool:YES] forKey:AVURLAssetPreferPreciseDurationAndTimingKey]];
AVAssetTrack *videoTrack = [[asset tracksWithMediaType:AVMediaTypeVideo] objectAtIndex:0];
This is where I run in to trouble. On the device where I took the video it works, but on another device, no file is found (objectAtIndex:0 is beyond bounds).
This is the metadata query I call at view did load:
NSMetadataQuery * query = [[NSMetadataQuery alloc] init];
NSString * filePattern = [NSString stringWithFormat:#"%#", self.video.url];
[query setPredicate:[NSPredicate predicateWithFormat:#"%K LIKE %#",
NSMetadataItemFSNameKey, filePattern]];
[query startQuery];
My metadata query may be at fault, or there may be more issues. Any help would be greatly appreciated!
I assume you are on iOS, which means on your second device the media file hasn't been downloaded (iOS doesn't download iCloud files until you actually access them, OS X downloads everything - see the docs).
To ensure the file is on the device use startDownloadingUbiquitousItemAtURL:error: or coordinateReadingItemAtURL:options:error:byAccessor: if you want to know when it's done (in the Accessor block). You will need to call the later anyway to do your coordinated read, so the first method has limited usefulness.
I use this code to post in facebook from my app in iphone
NSString *title=[NSString stringWithFormat:#"Posted from Poems of Love v2 iPhone/iPod/iPad touch app - { Poem Name: "];
//& titletext.text & ""\",";
NSString *alltitle= [title stringByAppendingString:poemtitle.text];
alltitle= [alltitle stringByAppendingString:#" } - { Author:"];
alltitle= [alltitle stringByAppendingString:authorname.text];
NSString *alltitle1= [alltitle stringByAppendingString:#" }"];
NSString *list = poembody.text;
NSString *kAppId=#"numid";
NSMutableDictionary* params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
kAppId, #"app_id",
#"http://www.poemsofloveapp.com", #"link",
#"http://3.bp.blogspot.com/_co4MVQE_2l0/TPRh6TBjaZI/AAAAAAAAAOg/E0kgWLd4ieE/s1600/poemsoflovev2logo.png", #"picture",
alltitle1, #"name",
#"\nhttp://www.poemsofloveapp.com - Join us on facebook!\n", #"caption",
list, #"description",
#"",#"message",
nil];
[mainDelegate._session dialog:#"feed" andParams:params andDelegate:self];
The dialog shows up i tap skip or publish and then a second dialog shows up which is empty! no message on it nothing
Why is this happening?
My mistake sorry guys i called [mainDelegate._session dialog:#"feed" andParams:params andDelegate:self];
two times previously stupid i know!!!
I have got a url http://stream.alayam.com/alayam/alayam/playlist.m3u8 and wanted to play in iPhone, with m3u8 format, I have successfully got the voice, however movie is not coming. I have used MPMEDIAPLAYER framework and other things.
I am giving u answer in new answer because code will be more readable.
I just download MPMovieController example from Apple website and then add your link with http://
In NSURL i pass link http://stream.alayam.com/alayam/alayam/playlist.m3u8 not this one stream.alayam.com/alayam/alayam/playlist.m3u8 and it works fine.
-(void)initAndPlayMovie:(NSURL *)movieURL
{
// Initialize a movie player object with the specified URL
MPMoviePlayerController *mp = [[MPMoviePlayerController alloc] initWithContentURL:movieURL];
if (mp)
{
// save the movie player object
self.moviePlayer = mp;
[mp release];
// Apply the user specified settings to the movie player object
[self setMoviePlayerUserSettings];
// Play the movie!
[self.moviePlayer play];
}
}
I'm trying to put two MPMoviePlayerController on a UIView like this
for (int i = 0; i < 2; i++)
{
UIView* v = [[UIView alloc] initWithFrame: CGRectMake(0.0f, 300.0f * i, self.view.width, 300.0f)];
[self.view addSubview: v];
NSURL* url = [NSURL URLWithString: [urls objectAtIndex: i]];
MPMoviePlayerController* movieController = [[MPMoviePlayerController alloc] initWithContentURL: url];
movieController.movieSourceType = MPMovieSourceTypeFile;
movieController.shouldAutoplay = NO;
movieController.view.frame = v.bounds;
[self.view addSubview: movieController.view];
}
But only one view at a time is shown. I know Apple's documentation says
Note: Although you may create multiple MPMoviePlayerController objects and present their views in your interface, only one movie player at a time may play its movie.
but shouldn't the view show all two players at a time? Also only one instance sends MPMoviePlayerLoadStateDidChangeNotification notifications...
You can play multiple videos on the screen by using the AVFoundation framework: AV Foundation Programming Guide
The downside is, that it is not as easy to use as the MPMoviePlayerController, and you shoul create a UIView subclass which contains the AVFoundation classes. This way you can create the necessary controls for it, control the video playback, animate the view (for example animate the transition to fullscreen).
Here it is how I used it:
// Create an AVURLAsset with an NSURL containing the path to the video
AVURLAsset *asset = [AVURLAsset URLAssetWithURL:url options:nil];
// Create an AVPlayerItem using the asset
AVPlayerItem *playerItem = [AVPlayerItem playerItemWithAsset:asset];
// Create the AVPlayer using the playeritem
AVPlayer *player = [AVPlayer playerWithPlayerItem:playerItem];
// Create an AVPlayerLayer using the player
AVPlayerLayer *playerLayer = [AVPlayerLayer playerLayerWithPlayer:player];
// Add it to your view's sublayers
[self.layer addSublayer:playerLayer];
// You can play/pause using the AVPlayer object
[player play];
[player pause];
// You can seek to a specified time
[player seekToTime:kCMTimeZero];
// It is also useful to use the AVPlayerItem's notifications and Key-Value
// Observing on the AVPlayer's status and the AVPlayerLayer's readForDisplay property
// (to know when the video is ready to be played, if for example you want to cover the
// black rectangle with an image until the video is ready to be played)
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(playerItemDidReachEnd:)
name:AVPlayerItemDidPlayToEndTimeNotification
object:[player currentItem]];
[player addObserver:self forKeyPath:#"currentItem.status"
options:0
context:nil];
[playerLayer addObserver:self forKeyPath:#"readyForDisplay"
options:0
context:nil];
You can resize the AVPlayerLayer as you like, even while the video is playing.
If you want to use animations while resizing or repositioning your AVPlayerLayer, you have to alter it's default animations, otherwise you'll see that the player layer's video is not resized in sync with its rect. (Thanks to #djromero for his answer regarding the AVPlayerLayer animation)
Here is a small example for how to alter its default animation. The setup for this example is that the AVPlayerLayer is in a UIView subclass that acts as its container:
// UIView animation to animate the view
[UIView animateWithDuration:0.5 animations:^(){
// CATransaction to alter the AVPlayerLayer's animation
[CATransaction begin];
// Set the CATransaction's duration to the value used for the UIView animation
[CATransaction setValue:[NSNumber numberWithFloat:0.5]
forKey:kCATransactionAnimationDuration];
// Set the CATransaction's timing function to linear (which corresponds to the
// default animation curve for the UIView: UIViewAnimationCurveLinear)
[CATransaction setAnimationTimingFunction:[CAMediaTimingFunction
functionWithName:kCAMediaTimingFunctionLinear]];
self.frame = CGRectMake(50.0, 50.0, 200.0, 100.0);
playerLayer.frame = CGRectMake(0.0, 0.0, 200.0, 100.0);
[CATransaction commit];
}];
You won't be able to do this. Internally MPMoviePlayerController seems to use the same view to trade between instances depending on whatever instance is playing. Your only option is to develop your own video player using AVFoundation in order to get multiple instances, or use HTML and UIWebViews. See: http://developer.apple.com/library/ios/#documentation/AudioVideo/Conceptual/AVFoundationPG/Articles/00_Introduction.html#//apple_ref/doc/uid/TP40010188
Do you require to play both the videos simultaneously?
I guess i have two options:
Add two video thumbnail image buttons on the same screen. According to selection selected video gets played and other gets stopped. So at a time in view only single video will gets played.
Create one separate view controller and add your video into that. Now add that viewcontroller.view in your main view wherever you want.
Let me know if any of these work for you.