I have a NavigationViewController which is holding a a table of Streams that could be played. When user selects one of the streams it push's the 'RadioDetailViewController' and start streaming from URL.
What I want is when I navigate back to the rootViewController(NavigationViewController) I want the AVPlayer to carry on streaming.
Anyone able to help?
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
UINavigationController *navController = [segue destinationViewController];
RadioTableViewController *radioTableViewController = (RadioTableViewController *)([navController viewControllers][0]);
[radioTableViewController setRadioStreamContinue:radioStream];
}
Then in my rootViewController I do this:
- (void)viewDidLoad{
[radioStreamContinue play];
[super viewDidLoad];
}
This doesn't do anything and the stream stops. Sorry I'm new this and would appreciate any help.
I stumbled on this trying to look for a cleaner solution... but have you tried setting the audio player property in the app delegate and setting it with resources from the view controller? This way the player object isn't released when the view controller is deallocated.
(I wouldn't really consider this a great answer but I don't have the rep to comment yet)
Related
Here is my Project Overview ->
I have a viewcontroller(class A) for music list, from there user tap a music and then a url sent to another viewcontroller(class Audioplayer). and Audioplayer class play the song.
code start:
- (void) didSelectItem:(ListItem *)item {
AudioPlayerViewController *apvc = [[AudioPlayerViewController alloc] init];
apvc.songurl = item.urls;
[self presentModalViewController:apvc animated:YES];
}
code end.
in Audioplayer class have a back button in navigation bar. when back button pressed this code execute
-(IBAction)back:(id)sender
{
[self dismissViewControllerAnimated:YES completion:nil];
}
Now the problem is I have a "Now Playing" Button In class A Navigation Bar(like iphone Music Apps) and i want to navigate Audioplayer class with all controll in current state by pressing "Now Playing" Button.
Note That i have already try this But it create a new AudioPlayer class object with new controlles.
code is here
-(void) Player{ AudioPlayerViewController *audvc = [[AudioPlayerViewController alloc] init];
[self presentViewController:audvc animated:YES completion:nil];}
but i want that view that i already dismiss by pressing back Button.
Experts please help Me, if you not understand my problem then please knok me, sorry for my bad english.
This AudioPlayerViewController is already created in your storyboard so you shouldn't instantiate it like this.
You could pass the data to your view controller by asking the storyboard to return you a reference to it like this:
AudioPlayerViewController *apvc = [self.storyboard instantiateViewControllerWithIdentifier:#"TheVCIdentifier"];
apvc.songurl = item.urls;
//the presentModalViewController method is deprecated.
[self presentViewController:apvc animated:YES completion:nil];
You add the view controller's identifier in Interface Builder under the Identity Inspector > Storyboard ID.
Another option would be to create a manual segue with an identifier to your View Controller and implement the prepareForSegue method in the View Controller you're transitioning from and implement it like this:
- (void) didSelectItem:(ListItem *)item {
[self performSegueWithIdentifier:#"YourSegueIdentifier" sender:self];
}
and in the prepareForSegue method:
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([segue.identifier isEqualToString:#"YourSegueIdentifier"]) {
AudioPlayerViewController *apvc = [segue destinationViewController];
apvc.songurl = item.urls;
}
}
You can check Apple's documentation on this matter here and here
It has been some months that I've programmed for iOS, and want to finish my game with new features. Now when people play the game and lose they will see a "Game Over" view.
Now what I want is that people first see a view where they can use the bought credits they gotten and go back to the game with the extra seconds or life. But I'm not doing it on the right way.
Way I'm trying to do:
- Save Me View (Segue)
Game view -
- Game Over View (Segue)
So, you lose, go automatically to the save me view, presses close and go to game over immediately. Otherwise use the NSUserDefaults that has been saved before showing the Save Me view.
So I'm using NSUserDefaults for saving previous game levels/points etc and that is not the right way of doing and the flow is getting complicated.
Second try:
I've tried it but I'm stuck at the last step. Because I'm using Segue's and delegates, I don't know how to make my GameView the delegate of the SaveView, while the protocols are already there.. I've followed this: Passing Data between View Controllers
Now at step 6 it doesn't work because i'm using modal segue's with my UIViewControllers and no UINavigationControllers. I've this in my code atm:
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
if ([[segue identifier] isEqualToString:#"SaveMe"]){
SaveMeViewController *vc = [segue destinationViewController];
// Here needs to come that GameView (This Class) is the delegate for SaveMeViewController. Tried vc.delegate = self; but this doesn't work.
[self savePoints];
}
}
You could setup a delegate in the gave view that passes back how the game ended.
As my understanding use #property or delegate to pass data it will help you.
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([segue.identifier isEqualToString:#"SaveMe"]) {
SaveMeViewController * vc = segue.destinationViewController;
// create property in SaveMeViewController and access that property and pass values
vc.property = value to assgin;
}
}
I got a question to ask. Currently, dismissing GLKViewController is not deallocating the memory at all. Rather, it takes more memory whenever I move to the GLKViewController and dismiss it. My game starts at 100MB. Whenever I play a game, it adds up about 10MB. So, if I play it 10 times, it will be about 200MB in the end. It will crash eventually.
This is my only reference to the GLKViewController. I do not call it anywhere in my uiviewcontroller anywhere other than that. I use modal segue to move to glkviewcontroller.
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
Game *renderer = [segue destinationViewController];
[renderer setDelegate:self];
renderer.bomb = bomb;
}
And I dismiss it using [self dismissViewControllerAnimated:YES completion:nil]
Do you know how to fix this problem? It is wasting so much time right now. Thanks.
Hi in VC1 I have an NSMutableArray displaying results. I want to keep that array alive even when users clicks to a different tab (so they don't have to search again) until the user searches again.
I have a strong pointer to it, but it seems to unload when I leave the view.
Not much code to show (_resultsArray is set from a previous controller using delegates, so it loads with the results already)
- (void)viewDidLoad
{
[super viewDidLoad];
_resultsTableView.dataSource=self;
_resultsTableView.delegate=self;
[self.navigationController.navigationBar setHidden:YES];
}
//then standard tableview delegate methods...
This code is to try to figure out how to segue tab bar to share info.
(in prepareforsegue)
Currently in Search VC. Now I have results I want to give to resultsIndexVC. The code below attempts this.
This is placed in current (search VC) prepare for segue.
ResultsIndexViewController* vc = [[ResultsIndexViewController alloc] init];
UITabBarController* tbc = [segue destinationViewController];
vc = (ResultsIndexViewController *)[[tbc customizableViewControllers] objectAtIndex:1];
vc.SearchDelegate=self;//crash here (normally works if using regular segue)
vc.resultsArray = _temporaryResultsArray;
vc.originalQuery=_queryArray;
Thanks
Issue is that I was pushing a VC. Instead I used the tabbar (which doesnt release the object when switching tabs)
Currently I am working for an IPad application which shows a Slideshow on the first scene - realized with a paged UIScrollView. When I click on one page in the slideshow I want to push a new VC (to a new scene, which should present multiple thumbnails... a kind of detail layer if you want so).
How can I do this via segue? Currently I simply pulled out a new VC and connected the SlideshowVC with the the next VC in the scene - but nothing happens. I wrapped my head around a couple of tutorials but most of them use a button which is connected to the next VC. Is it able to simply connect the SlideshowVC with the next VC or do I really need to strap a button over the whole scrollview and connect the button with the next VC?
Currently my scene look like the following picture. The first one is a NavVC - the second the SlidehsowVC and the third the DetailVC.
If you don't want to connect the segue to a button, when you intercept the user interaction, just do this -
[self performSegueWithIdentifier:#"mySegueIdentifier" sender:self];
If you need to set anything up before you get there, use this -
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([[segue identifier] isEqualToString:#"mySegueIdentifier"]) {
MyViewController *myViewController = segue.destinationViewController;
// do something here
}
}