How can i stop all audio file with single button? - iphone

I am making a quiz app and i have set different background music in two UIView.
Now i have created button for stop the bachgrond music.
IBOutlet UIButton *soundoffbtn;
I stop the background music for firstview by
-(Void)SoundBtn{
[Avbackmusic stop];
}
It just stop in one view.
When i entered in secondView , background music for that view is started as it should be.
What i want is to stop the background music for whole app (both view) by just tapping the firstview's soundoffbtn
What should i do for that?
I am new to this..
Any help will be appreciated..
Thanks.

I didn't fully understand a question. But if you want the second view not to start playing sound after you switch off sound on first view then create an indicator variable in applicaton delegate that will indicate the sound on/off status for your app. Access that indicator before playing a sound. If it shows on, then play, if off, do not play.
For example in your app delegate create a variable
int soundIndicator;
#property (nonatomic) int soundIndicator;
#synthesize soundIndicator;
Then in your View controllers you can access that variable, it will be common for all application:
YourAppDelegate *appDelegate = (YourAppDelegate *)[[UIApplication sharedApplication] delegate];
if (appDelegate.soundIndicator == 0){ ... }

Related

Play a video inside a view using MPMoviePlayerController?

I am trying to play video inside a view so I can move it around, perform layout together with other views, but I can't seem to get it work to using MPMoviePlayerController. I came across this link on how to play video in portrait mode but this is not possible because the video source is coming from the web and should be playable in different platforms not only on iPhone.
I've been successful rotating the video and scaling it but it is still contained in a UIWindow which fills the whole screen. Is there a way to create an intermediate UIWindow but not visible in the current screen, so you can play the video there and probably add subviews and return everything as a UIView where I can place it anywhere? Similar to creating a CGGraphics context draw objects there and output as an image. This would also prevent the current screen from rotating from portrait to landscape.
----- 2010/06/22 06:10+08:00 ---
IN response to Jasarien's answer (below), actually it is possible to rotate and scale a video. After the video has preloaded it creates another instance of UIWindow which then becomes the keywindow at that moment. By creating a callback selector at MPMoviePlayerContentPreloadDidFinishNotification, it is possible to apply transform modification of the current keywindow.
-(void)myMovieFinishedPreloading:(NSNotification*)aNotification {
NSArray *windows = [[UIApplication sharedApplication] windows];
UIWindow *moviePlayerWindow = nil;
if ([windows count] > 1)
{
moviePlayerWindow = [[UIApplication sharedApplication] keyWindow];
}
CGAffineTransform transform = CGAffineTransformMakeScale(0.5, 0.5);
transform = CGAffineTransformRotate(transform, -90.0f*M_PI/180.0f);
[moviePlayerWindow setTransform:transform];
}
Now my question is now that its part of UIWindow and since UIWindow is a UIView subclass, is it possible to subview this UIView? Also I can't seem to disable the autorotate behavior upon preloading of the video.
Video on the iPhone is played fullscreen at all times. The iPad with iOS 3.2 has APIs that allow a video to be treated as a normal view.
For the iPhone, without writing your own video view you're not going to be able to get the functionality you want.
Check out AVPlayer and AVPlayerLayer.

iPhone Datepicker plays 'tick' sound

Does any of you know what event I can tap into on the DatePicker when the wheel moves.
I want to play a sound (got sound code) as the wheel spin. Just like the timer set picker in Apple's clock app.
All that is there is a single event for ValueChanges which only fires once, at the end of a wheel spin.
Thanks in advance
I'm not sure this is possible, as the sounds seem to be linked to the Keyboard Clicks in the phone settings. Maybe someone else has a solution, but it doesn't seem to be documented anywhere.
There is an undocumented method for doing this:
Disable UIPickerView sound
#import <UIKit/UIKit.h>
#interface SilentUIPickerView: UIPickerView
{ }
- (void) setSoundsEnabled: (BOOL) enabled;
#end
use this subclass and call [view setSoundsEnabled: NO]
the reason behind this is when your controller is load the datepickr is scrolling so in view did load
write this code.
NSDate *d = [[NSDate alloc] init];
[objDatePicker setDate:d animated:NO];

Sending a message to an object

I'm pretty new to Objective C but things are progressing well. However, I think I'm missing a key concept relating to how objects are created and messaged. I hope someone can help me.
I'm creating an iPhone app that simply creates a MPMusicPlayer, and starts playing a song from the que.
I create the music player (myPlayer) in the AppDelegate like so...
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
// Add the main view controller's view to the window and display.
[window addSubview:mainViewController.view];
[window makeKeyAndVisible];
// instantiate a music player
MPMusicPlayerController *myPlayer =
[MPMusicPlayerController applicationMusicPlayer];
// assign a playback queue containing all media items on the device
[myPlayer setQueueWithQuery: [MPMediaQuery songsQuery]];
// start playing from the beginning of the queue
[myPlayer play];
return YES;
}
This works fine. Now in the MainViewController I try to send myPlayer the command to skip to the next track
[myPlayer skipToNextItem];
However when I try to compile I get the message that myPlayer in undeclared.
What am I doing wrong? I can see how I could fix this in a procedural way (by creating the player in the MainViewController), but I'd like to understand what I have to do to get it working in and OOP way.
Cheers,
Richard
Most propably, the mPlayer object is unknown to your ViewController. There are two options for you:
Make the mPlayer a property of your app delegate
Make the mPlayer a property of your view controller subclass and set it to your mPlayer upon creation
In your appdelegates declaration, do:
#property(nonatomic, retain) MPMusicPlayerController *mPlayer;
In your appdelegates implementation, do:
#synthesize mPlayer;
In your viewcontroller, do:
MPMusicPlayerController *mPlayer = [[[UIApplication sharedApplication] delegate] mPlayer];

is there any animation can be set for opening of the video player in iphone?

I am new to iphone development.I have created a application which able to play a video from a url.Is there any animation can be set for opening of the video player in iphone?.The video is opened normally in landscape view. I want to show the opening of video player with some animation.Is there any way out?
NSURL *movieURL = [NSURL URLWithString:#"http://url of movie"];
if (movieURL)
{
if ([movieURL scheme])
{
MovietryAppDelegate *appDelegate = (MovietryAppDelegate *)[[UIApplication sharedApplication] delegate];
[appDelegate initAndPlayMovie:movieURL];
}
}
In the delegate class i have defined the initAndPlayMovie method.I used the Apple sample "movie player " for my reference.Thanks.
I guess you can create an UIImageView, and place a screenshot of the movie player on it. Then you can do some fancy effects by scaling the image view or changing its opacity. It may look like "opening".
After the movie is loaded, you will receive, MPMoviePlayerContentPreloadDidFinishNotification and now you can remove the image view.

How to play sound automatically when scrolling to the next page?

I'm using Page Control example from Apple. I want to be able to scroll horizontally to certain page and get the sound automatically play when viewing that page? And then sound stop when viewing the other page?
So, for example. On page 1, i have some texts. When i go to the next page which is on page 2, i want sound to be automatically play and stop when i go to page 3.
I'm planning to use If statements (since it's not that many pages) to determine which page will get the sound.
My question is simple. How do you get the sound play automatically when viewing certain page?
By the way, I'm planning to use System Sound.
I know how to play the sound using button. But how do you get it automatically - start when certain page appear and stop when moving to the next page.
Thank you in advance!
Edited:
I put in this code in ViewDidLoad but the sound played on sooner before it reach the page intended:
// Set the label and background color when the view has finished loading.
- (void)viewDidLoad {
pageNumberLabel.text = [NSString stringWithFormat:#"Page %d", pageNumber + 1];
self.view.backgroundColor = [MyViewController pageControlColorWithIndex:pageNumber];
if (pageNumber == 3) {
NSString *path = [[NSBundle mainBundle] pathForResource:#"crunch" ofType:#"wav"];
SystemSoundID soundID;
AudioServicesCreateSystemSoundID((CFURLRef)[NSURL fileURLWithPath:path], &soundID);
AudioServicesPlaySystemSound(soundID);
}
}
Why cant you make the sound go off when your desired viewControllers view goes on screen? You know when it goes on screen from the scrollViewDidScroll method and loadPage method (in the Page Control example). By looking at the methods in there you should be able to identify when you need to play the sound (because the specific view has come on the screen) and play it. Another approach would be to subclass UIViewController with something like UISoundViewController and have it play the sound on viewDidLoad.
-viewDidLoad is called once and only once* when the view controller's view property is loaded. You only add stuff that is called once and only once in this method.
Playing sound clearly isn't a once-and-only-once event. Put those into -viewDidAppear:.
*: Unless the view controller is deallocated.