Use of Undeclared indentifier - ios

An error came up with [mpc [[MPMoviePlayerController alloc]][[initWithContentURL:url]]]; it says initWithContentURL is a Undeclared Indentifier. How do I fix that?
import "ViewController.h"
#interface ViewController ()
{
MPMoviePlayerController *mpc;
}
#end
#implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (IBAction)playButton:(id)sender {
NSString *stringpath;[[NSBundle mainBundle]pathForResource:#"Lake Weekend September 13-14" ofType:#"m4v"];
NSURL *url = [[[NSURL fileURLWithPath:stringpath]
[mpc [[MPMoviePlayerController alloc]][[initWithContentURL:url]]];
[mpc setMovieSourceType:MPMovieSourceTypeFile];
[[self view ]addSubview:mpc.view];
[mpc setFullscreen:YES];
[mpc play];
}
#end

Your alloc/init of mpc looks all wrong. That line looks all garbled to me. I think that that line should read something like:
mpc=[[MPMoviePlayerController alloc] initWithContentURL: url];

You haven't declared url before using it? You're trying to use it within the declaration of it...
NSURL *url = [[[NSURL fileURLWithPath:stringpath]
[mpc [[MPMoviePlayerController alloc]][[initWithContentURL:url]]];
You should at least have a semi colon after the first line.. then you will be able to use url. Plus you would need to sort out your additional brackets, try this..
NSURL *url = [NSURL fileURLWithPath:stringpath];
mpc = [[MPMoviePlayerController alloc]initWithContentURL:url];

Related

passing video url using json in ios

hi I'm trying to view the videos from my server for that i have stored the video url in mysql database
using the json and php code I'm passing the url to the iOS but now I'm getting some problem here
previously using this same format fetching the images from my server but now i want to view the videos this is the first time im working on the videos not to able to get it
this is the code which i used to fetch the url form database and liking to the ios nsurl format
tabecell.m file code:
#import "vediopoliticalCell.h"
#import "vedios.h"
#implementation vediopoliticalCell
//#synthesize movieplayer,titile;
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
// Initialization code
}
return self;
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
[super setSelected:selected animated:animated];
// Configure the view for the selected state
}
-(void)setDataSource:(vedios *)inVideosObj
{
self.titile.text = inVideosObj.title;
NSURL *url =[NSURL URLWithString:inVideosObj.video];
NSURLRequest *request =[NSURLRequest requestWithURL:url];
connection =[[NSURLConnection alloc] initWithRequest:request delegate:self];
self.responseData = [[NSMutableData alloc]init];
}
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data;
{
[self.responseData appendData:data];
}
- (void)connectionDidFinishLoading:(NSURLConnection *)connection;
{
MPMoviePlayerController *play = [[MPMoviePlayerController alloc]initWithContentURL:self.responseData];
}
In this code:
- (void)connectionDidFinishLoading:(NSURLConnection *)connection;
{
MPMoviePlayerController *play = [[MPMoviePlayerController alloc]initWithContentURL:self.responseData];
}
im getting a waring called:
Incompatible pointer types sending 'NSMutableData ' to parameter of type Nsurl
previously for the image i using this code:
- (void)connectionDidFinishLoading:(NSURLConnection *)connection;
{
UIImage *image = [UIImage imageWithData:self.responseData];
self.thumbImageView.image = image;
}
now i dont know how to use for the videos please can anyone help me with this
thanks in advance
self.responseData is NSMutableData but MPMoviePlayerController needs url to load the video.
So, first you have to get url-string from data.
NSString *url =[NSString stringWithUTF8String:[responseData bytes]]
MPMoviePlayerController *play = [[MPMoviePlayerController alloc]initWithContentURL:[NSURL urlWithString:url]];
//Now present the MPMoviePlayerController
Try this
In setDataSource: method
-(void)setDataSource:(vedios *)inVideosObj
{
self.titile.text = inVideosObj.title;
NSURL *url =[NSURL URLWithString:inVideosObj.video];
MPMoviePlayerViewController *videoDeatilView = [[MPMoviePlayerViewController alloc] initWithContentURL:url];
//now you can present this videoDeatilView and
//[videoDeatilView.moviePlayer play]; will play the video
}

using buttons to open webviews

Hey guys, i'm trying to make the buttons on my project to open a different webview url. I'm new to iOS programming, but i've used andriod programming. Is this possible? I've a ready created another webview view that sits in the supporting files folder.
Here is my code below
Viewcontroller.m
#import "ViewController.h"
#implementation ViewController
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
#pragma mark - View lifecycle
-(void)viewDidLoad
{
NSString *urlString = #"http://www.athletic-profile.com/Application";
//Create a URL object.
NSURL *url = [NSURL URLWithString:urlString];
//URL Requst Object
NSURLRequest *webRequest = [NSURLRequest requestWithURL:url];
//Load the request in the UIWebView.
[webView loadRequest:webRequest];
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
}
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
}
- (void)viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:animated];
}
- (void)viewDidDisappear:(BOOL)animated
{
[super viewDidDisappear:animated];
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}
#synthesize webView;
#end
Add a button to your View then give a connection to it. In the action method just write your code
-(IBAction*)yourButtonActionMethod:(id)sender
{
[UIWebView *aWebView =[[UIWebView alloc] initWithFrame:CGRectMake(x,y,width,height)];
aWebView.delegate=nil;
NSString *urlString = #"http://www.athletic-profile.com/Application";
//Create a URL object.
NSURL *url = [NSURL URLWithString:urlString];
//URL Requst Object
NSURLRequest *webRequest = [NSURLRequest requestWithURL:url];
//Load the request in the UIWebView.
[aWebView loadRequest:webRequest];
[self.view addSubView:aWebView];
}
Firstly you can drag & drop UIButton in First Class & create action of that Button then create a new class for UIWebView in which you want to open you url named your choice which is subclass of UIViewController then into your .Xib or Storyboard you just drag & drop the UIWebView then create outlet of UIWebView after you write this code in first class of that button's action :-
- (IBAction *) firstButton:(id) sender
{
NSString *urlString = #"http://www.athletic-profile.com/Application";
//Create a URL object.
NSURL *url = [NSURL URLWithString:urlString];
//URL Request Object
NSURLRequest *webRequest = [NSURLRequest requestWithURL:url];
//Load the request in the UIWebView.
[webView loadRequest:webRequest];
}

iOS button not playing audio file on button tap

This is a newbie question.
I have a very simple app that is supposed to only play an audio file when a button on the main view is tapped.
I am using XCode version 4.6.
I added an audio file 'audioclip.wav' to my project. I have added the AVFoundation.framework.
My project only has ViewController.h and ViewController.m.
I double clicked and dragged from the button in the storyboard to the .h file using the assistant editor to create my IBAction connection.
My ViewController.h:
#import <UIKit/UIKit.h>
#import<AVFoundation/AVAudioPlayer.h>
#interface ViewController : UIViewController <AVAudioPlayerDelegate> {
}
- (IBAction)playAudio:(id)sender;
#end
My ViewController.m:
#import "ViewController.h"
#interface ViewController ()
#end
#implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (IBAction)playAudio:(id)sender {
AVAudioPlayer *audioPlayer;
NSString *audioPath = [[NSBundle mainBundle] pathForResource:#"audioclip" ofType:#"wav" ];
NSURL *audioURL = [NSURL fileURLWithPath:audioPath];
audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:audioURL error:nil];
[audioPlayer play];
}
#end
For whatever reason (probably something silly I left out) The audioclip.wav file does not play when I click the button. I have tested on the iPhone 6.1 simulator and on my device.
I think there is some problem with wav files. Some people seem to get it to work, but I've tried several different files and none of them play. The mp3 and m4a files that are commented out in the code below worked fine. There's no need to do anything with a delegate, it's optional.
#import "ViewController.h"
#import <AVFoundation/AVFoundation.h>
#interface ViewController ()
#property (strong,nonatomic) AVAudioPlayer *audioPlayer;
#end
#implementation ViewController
- (IBAction)playAudio:(id)sender {
//NSString *audioPath = [[NSBundle mainBundle] pathForResource:#"11 Prayer" ofType:#"mp3" ];
//NSString *audioPath = [[NSBundle mainBundle] pathForResource:#"Sunshine" ofType:#"m4a" ];
NSString *audioPath = [[NSBundle mainBundle] pathForResource:#"space" ofType:#"wav" ];
NSURL *audioURL = [NSURL fileURLWithPath:audioPath];
NSError *error;
self.audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:audioURL error:&error];
[self.audioPlayer play];
}
If I log the error, with the wav file I get:
Error Domain=NSOSStatusErrorDomain Code=1685348671 "The operation couldn’t be completed. (OSStatus error 1685348671.)"
Please try to use this one..
- (IBAction)playAudio:(id)sender
{
NSURL *url=[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:#"audioclip" ofType:#"wav"]];
NSData *data =[NSData dataWithContentsOfURL:url];
audioPlayer = [[AVAudioPlayer alloc] initWithData:data error:nil];
audioPlayer.delegate = self;
[audioPlayer setNumberOfLoops:0];
[audioPlayer play];
}
i hope this will help u
try like this ,
NSString *audio=[[NSBundle mainBundle]pathForResource:#"audioclip" ofType:#"wav"];
NSURL *url=[[NSURL alloc]initFileURLWithPath:audio];
avPlayer = [[AVAudioPlayer alloc]initWithContentsOfURL:url error:nil];
avPlayer.delegate = self;
[avPlayer prepareToPlay];
[avPlayer play];
and once check IBOutlet connected or not and check the button action method with breakpoints.
As i can see you have made the code quite simple, so the way it's made does require that it is not a big wav file.
And by that you need to cut down the audio file to something like 10 seconds and under.
I was using the .m4a when I encountered this problem. For me, not implementing AVAudioSession was the issue
var session = AVAudioSession.sharedInstance()
do {
session.setCategory(AVAudioSessionCategoryPlayAndRecord)
try session.setActive(true)
} catch {
gf.displayAlert("problem encountered", userMessageTitle: "")
self.navigationController?.popViewControllerAnimated(true)
}

Undeclared Identifier 'webview'

I am building a tab bar application with a different pdf in each tab. I have two sets of view controllers. Each have this relative code
#import "SecondViewController.h"
#interface SecondViewController ()
#end
#implementation SecondViewController
- (void)viewDidLoad
{
[super viewDidLoad];
NSString *path = [[NSBundle mainBundle] pathForResource:#"Winter_Newsletter"
ofType:#"pdf"];
NSURL *url = [NSURL fileURLWithPath:path];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[webView loadRequest:request];
[webview setScalesPageToFit:YES];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#end
I keep receiving an error "undeclared identifier 'web view'" What am I doing Wrong?
You are showing in the code two versions of webView(capital V) and webview(small v)
[webView loadRequest:request];
[webview setScalesPageToFit:YES];
And if you are using auto-synthesize then it sould be
self.webView or _webView
And also, don't forget to make a property of the web view and control drag to hook it up!

AVAudioPlayer not playing my mp3

I'm trying to get a short audio file (mp3) to play in my app. Here is the code i'm using:
AVAudioPlayer *AudioPlayer;
NSError *error;
NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle]
pathForResource:#"filename"
ofType:#"mp3"]];
AudioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:&error];
AudioPlayer.delegate = self;
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback error:nil];
if (error)
{
NSLog(#"Error: %#",
[error localizedDescription]);
}
else
{
[AudioPlayer play];
}
I don't really know what i'm missing, the examples i've followed seem to match what i'm doing.
edit: I should also mention that the code runs without error, there is a try catch around this.
I had a similar problem due to ARC. Instead of defining the AVAudioPlayer in the same method you are using it, you should should have an instance variable somewhere else, such as the UIViewController. This way ARC doesn't auto release this object and audio can play.
I've made some additions and got it work:
#import <UIKit/UIKit.h>
#import <AVFoundation/AVFoundation.h>
#interface FirstViewController : UIViewController <AVAudioPlayerDelegate> {
AVAudioPlayer *data;
UIButton *playButton_;
}
#property(nonatomic, retain) IBOutlet UIButton *playButton;
-(IBAction)musicPlayButtonClicked:(id)sender;
#end
#import "ViewController.h"
#implementation FirstViewController
#synthesize playButton=playButton_;
- (IBAction)musicPlayButtonClicked:(id)sender {
NSString *name = [[NSString alloc] initWithFormat:#"09 No Money"];
NSString *source = [[NSBundle mainBundle] pathForResource:name ofType:#"mp3"];
if (data) {
[data stop];
data = nil;
}
data=[[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath: source] error:NULL];
data.delegate = self;
[data play];
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#end
In Interface Builder I've added a button and connected it with IBOutlet and musicPlayButtonClicked IBAction.
And don't forget to add AVFoundation framework to your project.
ps
I'm really sorry for my english, please, be indulgent.
I had this problem myself, until I found out that the sound was not coming through the speakers (instead - it was redirected to the calls speaker). Try adding this to redirect the sound through the speakers:
UInt32 doChangeDefaultRoute = 1;
AudioSessionSetProperty (kAudioSessionProperty_OverrideCategoryDefaultToSpeaker,
sizeof (doChangeDefaultRoute),
&doChangeDefaultRoute);

Resources