How can I hide the volume bar in movie player and keep the other controls are appear (play, forward ... ) ? I want to show some videos that haven't any sounds, so the volume bar is totally will be useless.
can I do this ?
Thanks in advance
Set the controlStyle of the MPMoviePlayer to MPMovieControlStyleNone.
moviePlayer.controlStyle = MPMovieControlStyleNone;
But this will hide all the controls from the view.
After setting to MPMovieControlStyleNone, if you want to display the play/pause option and seek bar, You need to add custom controls.
(I did it before, I used slider as seek bar and and placed it in a UIToolBar along with a Tool bar button . Button is for play/pause option)
MPMovieControlStyle
Constants describing the style of the playback controls.
enum { MPMovieControlStyleNone, MPMovieControlStyleEmbedded,
MPMovieControlStyleFullscreen, MPMovieControlStyleDefault =
MPMovieControlStyleFullscreen }; typedef NSInteger
MPMovieControlStyle;
Constants
MPMovieControlStyleNone
No controls are displayed.
Available in iOS 3.2 and later.
Declared in MPMoviePlayerController.h.
MPMovieControlStyleEmbedded
Controls for an embedded view are displayed. The controls include a start/pause button, a scrubber bar, and a button for toggling
between fullscreen and embedded display modes.
Available in iOS 3.2 and later.
Declared in MPMoviePlayerController.h.
MPMovieControlStyleFullscreen
Controls for fullscreen playback are displayed. The controls include a start/pause button, a scrubber bar, forward and reverse
seeking buttons, a button for toggling between fullscreen and embedded
display modes, a button for toggling the aspect fill mode, and a Done
button. Tapping the done button pauses the video and exits fullscreen
mode.
Available in iOS 3.2 and later.
Declared in MPMoviePlayerController.h.
MPMovieControlStyleDefault
Fullscreen controls are displayed by default.
Available in iOS 3.2 and later.
Declared in MPMoviePlayerController.h.
Refer MPMoviePlayerController
There is no way to do this except "hacking" the subviews. You may subclass MPMoviePlayerViewController and iterate the subviews. In one of my apps, I used code like this to remove things like the media controls:
- (void)removeMediaControls
{
#try
{
// Search for the MPSwipeableView
for (UIView *view1 in [self.view subviews])
{
// Check for the MPSwipeableView
if ([[[view1 class] description] isEqualToString:#"MPSwipableView"])
{
// Search for the MPVideoBackgroundView
for (UIView *view2 in [view1 subviews])
{
// Check for the MPVideoBackgroundView
if ([[[view2 class] description] isEqualToString:#"MPVideoBackgroundView"])
{
// Search for the UIView
for (UIView *view3 in [view2 subviews])
{
// Check for the MPWildcatFullScreenVideoOverlay
if ([[[view3 class] description] isEqualToString:#"MPWildcatFullScreenVideoOverlay"])
{
// Search for the MPWildcatFullScreenNavigationBar
for (UIView *view4 in [view3 subviews])
{
// Check for the UIImageView
if ([[[view4 class] description] isEqualToString:#"UIImageView"])
{
// Remove the overlay
[view4 removeFromSuperview];
}
}
}
}
}
}
}
}
}
#catch (NSException * e)
{
}
}
The code above is too old, it worked with iOS 4.3. On iOS 5 and iOS 6 the view hierarchy changed, so you may have to updated your code with every new iOS version. See also: MPMoviePlayerController hide volume slider
Related
I am using the following code to remove the toolbar from the iPhone keyboard when it is displayed.
- (void) keyboardDidShowNotification:(NSNotification *)aNotification {
NSArray *array = [[UIApplication sharedApplication] windows];
for (UIWindow* wind in array) {
for (UIView* currView in wind.subviews) {
if ([[currView description] hasPrefix:#"<UIPeripheralHostView"]) {
for (UIView* perView in currView.subviews) {
if ([[perView description] hasPrefix:#"<UIWebFormAccessory"]) {
[perView removeFromSuperview];
}
}
}
}
}
}
This is removing the toolbar like I want but it is still leaving a 1px border above where the toolbar use to be. How do I remove that as well?
Also this only appears to be an issue on iPhone Retina displays. iPhone 3GS and iPad Retina do not have it.
Seems to be a bug in removeFromSuperView. I had the same problem when adding a toolbar as an input accessory view to some pickers for inline editing. Calling 2x removeFromSuperView left the border.
Using [self.view endEditing:YES] when closing the picker helped to clean up the picker and the accessory view attached to it, with no border. Perhaps this can point you into the right direction?
I've put a MPVolumeView over a movie I'm playing. The trouble is, whenever I adjust the vol using the MPVolumeView, then the standard grey volume overlay appears (the one that appears when you use the rocker switch on the iPhone). Is there a way to disable the standard grey overlay?
I might be a bit late, but I think I have something useful to add. If you're just looking for an answer, skip to How did I fix it?
What is MPVolumeView?
The MPVolumeView class is used to put a slider onscreen that controls the system volume. It's supposed to prevent the system volume overlay from appearing while it is onscreen, but sometimes does not. I ran into this issue when I added my own MPVolumeView to the view hierarchy, but still saw the overlay appear when I dragged the slider.
How does MPVolumeView tell when it is visible?
This is the question I asked myself. Somehow, the class detects whether or not it is visible, and tells the system to hide or display the system volume overlay accordingly. This is because Apple does not really want you using the class just to prevent the overlay from appearing, without actually displaying the slider UI to the user (as in myell0w's answer).
Here's how I believe MPVolumeView tries to check if it is really visible:
When the view is added to a superview, as detected by viewWillMoveToSuperview: and viewDidMoveToSuperview, it starts a short timer.
When the timer fires, the view traverses its view ancestor tree by recursively examining the superview property.
MPVolumewView checks that each of its ancestors has hidden = NO and alpha greater than some small value (likely 0.05).
There could be other checks that I'm not aware of, since this code is of course closed-source. The timer in step 1 is there so that code like the following will not "fool" the view:
MPVolumeView *volView = [[MPVolumeView alloc] init];
[self.view addSubview:volView];
volView.hidden = YES;
because it will check the hidden property not immediately, but in a bit, after it is already set to YES.
How did I figure all of this out? A key find was that the instance of MPVolumeView was calling isHidden on its superview, as shown in the following stack trace:
What was my problem?
In short, I did something like this:
- (void)viewDidLoad {
// Add an MPVolumeView to my view
self.volView = [[MPVolumeView alloc] init];
[self.view addSubview:self.volView];
self.volView.hidden = YES;
}
- (void)someButtonTouched {
// Show the MPVolumeView (and hopefully hide the system overlay)
self.volView.hidden = NO;
}
But when I dragged the slider of the newly revealed MPVolumeView, the overlay still appeared. I realized that this was because during the MPVolumeView's instantiation, its superview was hidden.
How did I fix it?
Once I had realized how the MPVolumeView class judged whether it was visible, I had an easy way to "fool" it. I added the following method to the class responsible for the MPVolumeView:
- (void)refreshVolumeView {
[self.volView willMoveToSuperview:self];
[self.volView didMoveToSuperview];
}
and called it each time I need to force the view to reevaluate whether it was visible. This method simply pretends to re-add the view to the hierarchy. Once I've satisfied the conditions that the view evaluates (each ancestor is not hidden or of very low alpha), I call it, and the overlay stops showing up. In my example code above, I would add one line:
- (void)viewDidLoad {
// Add an MPVolumeView to my view
self.volView = [[MPVolumeView alloc] init];
[self.view addSubview:self.volView];
self.volView.hidden = YES;
}
- (void)someButtonTouched {
// Show the MPVolumeView (and hopefully hide the system overlay)
self.volView.hidden = NO;
[self refreshVolumeView]; // <<< This line was added
}
Normally when a MPVolumeView is visible the HUD doesn't appear. I'm using the following method in my App and it is working fine:
+ (void)preventSystemVolumePopup {
// Prevent Audio-Change Popus
MPVolumeView *volumeView = [[MPVolumeView alloc] initWithFrame:CGRectMake(-2000., -2000., 0.f, 0.f)];
NSArray *windows = [UIApplication sharedApplication].windows;
volumeView.alpha = 0.1f;
volumeView.userInteractionEnabled = NO;
if (windows.count > 0) {
[[windows objectAtIndex:0] addSubview:volumeView];
}
}
It basically just adds a volume view to the first window at a position where nobody can see it and thus prevents the system volume HUD from showing. I wonder why you see this HUD, even though you put a volume view above your movie.
This may help.
-(void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
self.volumeView.hidden = NO;
[self.volumeView willMoveToSuperview:self.volumeView.superview];
[self.volumeView didMoveToSuperview];
}
Easiest way to do this.....
- (void) viewDidLoad
{
[super viewDidLoad];
MPVolumeView *volumeView = [[MPVolumeView alloc] initWithFrame: CGRectZero];
[self.view addSubview: volumeView];
...
}
taken refrence from this thread applicationMusicPlayer volume notification
i use this code to display a video in my app
NSURL *movieUrl = [NSURL fileURLWithPath:
[[NSBundle mainBundle] pathForResource:#"myvideoname"
ofType:#"mp4"]];
//create a new instance of MPMoviePlayerController
MPMoviePlayerController* myMovie=[[MPMoviePlayerController alloc]
initWithContentURL:movieUrl];
//disable scaling of our movie
myMovie.scalingMode = MPMovieScalingModeNone;
[myMovie.view setFrame: myView.bounds]; // player's frame must match parent's
[myView addSubview: myMovie.view];
[[myMovie view] setFrame:[myView bounds]];
//don't show any controls
// myMovie.movieControlMode = MPMovieControlModeHidden;
//you can specify at which time the movie should
//start playing (default is 0.0)
myMovie.initialPlaybackTime = 2.0;
//register a callback method which will be called
//after the movie finished
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(movieFinished:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:myMovie];
myMovie.scalingMode = MPMovieScalingModeAspectFill;
//start the movie (asynchronous method)
[myMovie play];
// Do any additional setup after loading the view from its nib.
it work fine but i want to add the controls ( play , stop , sound control ...)
How can i do ? thanx
What using controlStyle?
myMovie.constrolStyle = MPMovieControlStyleEmbedded;
MPMovieControlStyle
Constants describing the style of the playback controls.
enum {
MPMovieControlStyleNone,
MPMovieControlStyleEmbedded,
MPMovieControlStyleFullscreen,
MPMovieControlStyleDefault = MPMovieControlStyleFullscreen
};
typedef NSInteger MPMovieControlStyle;
Constants
MPMovieControlStyleNone
No controls are displayed. Available in
iOS 3.2 and later. Declared in
MPMoviePlayerController.h.
MPMovieControlStyleEmbedded
Controls for an embedded view are displayed.
The controls include a start/pause
button, a scrubber bar, and a button
for toggling between fullscreen and
embedded display modes. Available in
iOS 3.2 and later. Declared in
MPMoviePlayerController.h.
MPMovieControlStyleFullscreen
Controls for fullscreen playback are displayed.
The controls include a start/pause
button, a scrubber bar, forward and
reverse seeking buttons, a button for
toggling between fullscreen and
embedded display modes, a button for
toggling the aspect fill mode, and a
Done button. Tapping the done button
pauses the video and exits fullscreen
mode. Available in iOS 3.2 and later.
Declared in MPMoviePlayerController.h.
MPMovieControlStyleDefault
Fullscreen controls are displayed by default.
Available in iOS 3.2 and later.
Declared in MPMoviePlayerController.h.
MPMovieFinishReason
You should set the control style, like myMovie.controlStyle = MPMovieControlStyleDefault; to add a control bar.
Define the controlStyle property on the MPMoviePlayerController object.
Constants describing the style of the playback controls.
enum {
MPMovieControlStyleNone,
MPMovieControlStyleEmbedded,
MPMovieControlStyleFullscreen,
MPMovieControlStyleDefault = MPMovieControlStyleFullscreen
};
typedef NSInteger MPMovieControlStyle;
Read more from here
I am building an app that has picture viewing capabilities. I have wrestled the UIScrollView beast to the ground (hope to post my scrollview knowledge RSN) and am now trying to duplicate some of the other visual effects of the iPhone photos app. specifically, when viewing an image, I would like to dissolve the controls and bars away.
I have a method that toggles visibility of the status bar, navigation bar, and tab bar, leaving just the scrollview with an image. The scrollview is full screen. I have a timer that fires 3 seconds after the user does something (single taps the screen, views the next image, etc.) and in the timerFired method, I call my method to turn off the bars. a single tap of the screen turns on the bars. here's the method to toggle the full screen state.
- (void)setFullScreen:(BOOL)fullScreen {
// reset the timer
[myTimer invalidate];
[myTimer release];
myTimer = nil;
// start animation section
[UIView beginAnimations:nil context:nil];
// toggle the status bar
[[UIApplication sharedApplication] setStatusBarHidden:fullScreen animated:YES];
[UIView setAnimationDuration:UINavigationControllerHideShowBarDuration];
CGFloat alpha = fullScreen ? 0.0 : 1.0;
// change the alpha to either 0 or 1 based on hiding or showing the bars
self.navigationController.navigationBar.alpha = alpha;
self.tabBarController.tabBar.alpha = alpha;
// do the animations!
[UIView commitAnimations];
// restart the timer after we show the bars
if (!fullScreen) {
myTimer = [[NSTimer timerWithTimeInterval:3.0 target:self selector:#selector(timerFired:) userInfo:nil repeats:NO] retain];
[[NSRunLoop currentRunLoop] addTimer:myTimer forMode:NSDefaultRunLoopMode];
}
}
This basically works, BUT, it doesn't look as good as the photos app. I am animating the alpha values as I believe that this looks more like the photos app instead of the using the hidden with Animation methods available. My problem is doing the same for the status bar.
my questions:
(1) is there a UIView for the the status bar?
(2) is there a way to change the alpha property of the status bar?
(3) is the statusbar in another UIWindow?
(4) is there another way to achieve this using "legal" methods (I need to put this app in the app store)?
I've dumped the windows property of the UIApplication and there was only 1 window and I've crawled the view hierarchy and there was not an obvious view for the status bar.
any ideas?
The status bar is created by SpringBoard itself, it is of class SBStatusBar (which IIRC inherits from UIWindow). It is not accessible to app store applications.
could you show me some algorithm or example code to display like that picture with or with out animation
thanks for all advise
Add a semi-transparent view (regular view with black background with opacity = 80) that will cover the entire screen (in IB or in code), add a UIActivityIndicator and a label to the semi-transparent view, set it hidden.
If you use the IB then you should also create IBOutlets for the semi-transparent view (loadingView) and for the activity indicator (loadingAnimationIndicator)...
Use the next methods to show / hide the "loading view":
- (void)showLoading {
[loadingAnimationIndicator startAnimating];
loadingView.hidden = NO;
}
- (void)hideLoading {
loadingView.hidden = YES;
[loadingAnimationIndicator stopAnimating];
}