how to create player sound UISlider to be UIProgress - ios

I want one application that to play sound file and show it in UIProgress when to play music.
I have to use UISlider instead UIProgress (for example I want can further this sound or Rewind it with UISlider like music player in iphone)
I could create one application that play music with UIProgress but I want could further or rewind this music with touch and push.
please guide me and tell me about it.

- (void)viewDidLoad
{
[super viewDidLoad];
durationControl= [[UISlider alloc]initWithFrame:CGRectMake(65, 250 , 130, 10)];
// durationControl.maximumValue = 130;
[durationControl addTarget:self action:#selector(changeDuration) forControlEvents:UIControlEventValueChanged];
[durationControl setThumbImage:[self imageNamed:#"trackbutton"] forState:UIControlStateNormal];
[durationControl setThumbImage:[self imageNamed:#"trackbutton1"] forState:UIControlStateHighlighted];
[self.view addSubview:durationControl];
}
-(void)ffwAudio{
[player changeDuration:durationControl.value+=5];
durationControl.value = player.currentTime;
}
-(void)bwAudio{
if (durationControl.value>=5) {
[player changeDuration:durationControl.value-=5];
durationControl.value = player.currentTime;
}
-(void)changeDuration:(double)value{
player.currentTime = value;
durationControl.value = player.currentTime;
}

Related

How to add MPMoviePlayerController on current view with animation

I am using MPMoviePlayerController to play a video inside my iPad application. I am using below code snippet to add the movie player to view:
self.player =[[MPMoviePlayerController alloc] initWithContentURL: urlVideo];
[self.player prepareToPlay];
[self.player setMovieSourceType:MPMovieSourceTypeStreaming];
[self.player.view setBounds:CGRectMake(0, 0, 512, 374)];
if (UIDeviceOrientationIsLandscape([UIApplication sharedApplication].statusBarOrientation))
{
NSLog(#"landscape..");
[self.player.view setCenter:CGPointMake(512, 374)];
}
else{
NSLog(#"portrait.");
[self.player.view setCenter:CGPointMake(384, 502)];
}
self.player.controlStyle=MPMovieControlStyleEmbedded;
[self.player setScalingMode:MPMovieScalingModeAspectFit];
self.player.shouldAutoplay=YES;
[self.viewController.view addSubview: self.player.view];
self.btnCloseNormalMode= [UIButton buttonWithType:UIButtonTypeCustom];
[self.btnCloseNormalMode setImage:[UIImage imageNamed:#"close_button_icon.png"] forState:UIControlStateNormal];
[self.btnCloseNormalMode setFrame:CGRectMake(470, 5, 32, 32)];
[self.btnCloseNormalMode addTarget:self action:#selector(onSmallCloseBtnTap) forControlEvents:UIControlEventTouchUpInside];
[self.player.view addSubview:self.btnCloseNormalMode];
But as understandable from the above code, its adding on the view abruptly. Suddenly one black view appears on the view which is not user friendly. We want to add the movie player view with some animation to make it smooth. Can I make the movie player view to come with a animation like how modal appears or any suitable UIView animation. But I have no idea regarding animation. Could someone please help me on this !!! Thanks.

MPMoviePlayerViewController hides StatusBar and destroys Frame after watching

i created a MPMoviePlayerViewController in my UIView (not in my UIVIewController!) like this:
self.playButton = [[UIButton alloc] initWithFrame:CGRectMake(100, 70, 125, 100)];
[self.playButton setBackgroundImage:[UIImage imageNamed:#"video_play.png"] forState:UIControlStateNormal];
[self.playButton addTarget:self action:#selector(buttonPressed:) forControlEvents: UIControlEventTouchUpInside];
self.playerViewController = [[MPMoviePlayerViewController alloc] initWithContentURL:videoURL];
self.playerViewController.moviePlayer.fullscreen = NO;
self.playerViewController.view.frame = CGRectMake(0, 0, 320, 200);
[self.playerViewController.moviePlayer prepareToPlay];
self.playerViewController.moviePlayer.shouldAutoplay = NO;
self.playerViewController.view.backgroundColor = [UIColor yellowColor];
[self addSubview:self.playerViewController.view];
[self.playerViewController.view addSubview:self.playButton];
}
- (void)buttonPressed:(id)sender{
(NSLog(#"Click"));
[self.playerViewController.moviePlayer setFullscreen:YES animated:YES];
[self.playerViewController.moviePlayer play];
}
As you can see i added a Button on the videoView, beacause this part should only be a Preview and when the user clicks on the Button the MPMoviePlayerViewController should animate to fullscreen and start playing, and when the Video is finished it should go back to the Preview View. Everything works so far, but i have two Problems:
First Problem:
Everytime i open the View my StatusBar becomes hidden and it looks like this:
So i set in my viewWillAppear and viewDidAppear of my UIViewController:
[[UIApplication sharedApplication] setStatusBarHidden:NO withAnimation:UIStatusBarAnimationNone];
This works, but now the statusbar gets hidden and immediately appears again, that looks ugly, any chance to solve this Problem?
Second Problem:
When i click on the Custom Button the Video gets fullscreen and everything works correct! But when i press the DONE Button of the Video everything goes back to the Preview Screen and it looks like this: The StatusBar is hidden, the navigationbar is also broken and there is a lot of black Space above the Video, whats the Problem here?
Ok i found a solution for this Problem, its a little bit hacky but i found no other solution. In my ViewController i do:
- (void)viewDidLoad {
[super viewDidLoad];
float delay = 0.1;
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, delay * NSEC_PER_SEC), dispatch_get_main_queue(), ^{
[UIApplication sharedApplication].statusBarHidden = NO;
});
and for the case User taps back Button i do:
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
[UIApplication sharedApplication].statusBarHidden = NO;
}

Controls not working in MPMoviePlayerController

I'm working on a project in which, video will be played when a button is clicked. MPMoviePlayer worked fine before I use this button action. But after implementing that, Video plays fine but the player doesn't recognise touch and it doesn't even shows playback time. Only showing like this ( - - ).
I'm working on this code:
-(void) sceneBegins:(id)sender
{
....
theMoviePlayer = [MPMoviePlayerController new];
[theMoviePlayer setContentURL:movieURL];
theMoviePlayer.controlStyle = MPMovieControlStyleEmbedded;
theMoviePlayer.backgroundView.hidden = YES;
[theMoviePlayer setMovieSourceType:MPMovieSourceTypeFile];
theMoviePlayer.shouldAutoplay = YES;
[theMoviePlayer prepareToPlay];
[theMoviePlayer.view setFrame:View.bounds];
[theMoviePlayer.view setUserInteractionEnabled:YES];
theMoviePlayer.scalingMode = MPMovieScalingModeAspectFit;
[View addSubview:theMoviePlayer.view];
theMoviePlayer.view.autoresizingMask = UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight;
[theMoviePlayer play];
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(sceneChange:)
name:MPMoviePlayerPlaybackDidFinishNotification object:theMoviePlayer];
....
}
Also it doesn't enters in to the stop notification method when the video stops playing.
Try this line of code :-
[myButton addTarget:self action:#selector(dragEnded:withEvent: )
forControlEvents: UIControlEventTouchUpInside |
UIControlEventTouchUpOutside];

Mpmovieplayercontroller video pause while clicking button for another functionality

i am using MPMovieplayerController for playing video, while im clicking some other button i.e i want to pause my video wherever its playing again. i click play means i want to play while its pausing.But for me now when i click button means my video was stopped.But i want to pause instead of stop.
My sample code here
- (IBAction) playvideo
{
NSURL *url = [NSURL URLWithString:#"http://xyz/video1.mp4"];
movieplayer = [[[MPMoviePlayerController alloc]initWithContentURL:url] retain];
movieplayer.view.frame=CGRectMake(25,54,658,460);
[self.view addSubview:movieplayer.view];
[movieplayer play];
}
-(void)buttononclick
{
[movieplayer pause];
[movieplayer.view removeFromSuperview];
for (int i = 0; i < 13; i++)
{
CGRect frame;
frame.origin.x = 150 * i;
frame.origin.y = 0;
frame.size = CGSizeMake(140, self.scrollView.frame.size.height);
[scrollView setShowsHorizontalScrollIndicator:NO];
UIImageView *temp1 = [[UIImageView alloc] initWithFrame:CGRectMake(25, 7, 75, 75)];
[temp1 setImage:[UIImage imageNamed:#"sti15.png"]];
[self.scrollView addSubview:temp1];
UIImageView *temp2 = [[UIImageView alloc] initWithFrame:CGRectMake(110, 7, 75, 75)];
[temp2 setImage:[UIImage imageNamed:#"sti16.png"]];
[self.scrollView addSubview:temp2];
UIImageView *temp3 = [[UIImageView alloc] initWithFrame:CGRectMake(195, 7, 75, 75)];
[temp3 setImage:[UIImage imageNamed:#"sti17.png"]];
[self.scrollView addSubview:temp3];
}
self.scrollView.contentSize = CGSizeMake(165 * 10, self.scrollView.frame.size.height);
self.scrollView.pagingEnabled=0;
}
- (void)viewDidDisappear:(BOOL)animated
{
// [self setDescText:nil];
[super viewDidDisappear:animated];
[movieplayer pause];
[movieplayer.view removeFromSuperview];
}
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
if ((movie.playbackState==MPMoviePlaybackStateStopped)||(movie.playbackState==MPMoviePlaybackStatePaused))
{
[movie play];
}
else
{
[movie pause];
}
}
Try this Code , it will Work
Check out the notifications for MPMoviePlaybackStatePlaying, MPMoviePlaybackStateStopped, MPMoviePlaybackStatePaused, and MPMoviePlaybackStateInterrupted.
Something like:
MPMoviePlayerController *player = notification.object;
/* Playback is currently stopped. */
if (player.playbackState == MPMoviePlaybackStateStopped)
{
NSLog(#"MPMoviePlaybackStateStopped");
}
/* Playback is currently under way. */
else if (player.playbackState == MPMoviePlaybackStatePlaying)
{
NSLog(#"MPMoviePlaybackStatePlaying");
}
/* Playback is currently paused. */
else if (player.playbackState == MPMoviePlaybackStatePaused)
{
NSLog(#"MPMoviePlaybackStatePaused");
}
You can wire up your target action something like this:
if ((_moviePlayer.playbackState == MPMoviePlaybackStateStopped) || (_moviePlayer.playbackState == MPMoviePlaybackStatePaused)) {
[_moviePlayer play];
} else {
[_moviePlayer pause];
}
you can add target to the play/pause button.
but first you need to catch the button of the mpmovieplayerview.
step 1 list the button. method reference from here
call this method from when the button appear(the video is ready).
But remember, this will also catch the full screen button and airplay button.(if available)
- (void)CatchSubviewsOfView:(UIView *)view {
// Get the subviews of the view
NSArray *subviews = [view subviews];
for (UIView *subview in subviews) {
// Do what you want to do with the subview
NSLog(#"%#", subview);
if(subview isKindOfClass:[UIButton class]]){
// add your target here
[subview addTarget:self action:#selector(extraAction:) forControlEvents:UIControlEventTouchUpInside];
}
// List the subviews of subview
[self listSubviewsOfView:subview];
}
}
step 2 implement the action
-(IBAction)extraAction:(id)sender{
NSLog(#"some extraAction");
}
call the catch method sample.
[self CatchSubviewOfView:movieplayer.view];

Failed to play a youtube video in iPad

I am currently trying to play a youtube video in iPad but device only display blank screen.
- (void)viewDidLoad {
[super viewDidLoad];
NSURL* videoURL = [NSURL URLWithString:#"http://www.youtube.com/......."];
MPMoviePlayerController * moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:videoURL];
[moviePlayer prepareToPlay];
[moviePlayer play];
[moviePlayer.view setFrame:CGRectMake(50, 200, (self.view.frame.size.width)-100 , 400)];
moviePlayer.view.backgroundColor = [UIColor grayColor];
[self.view addSubview:moviePlayer.view];
}
This will just display a blank gray screen,But if i try to play any locally stored video file then i can able to play by MPMoviePlayerController.So what is the best way to play a youtube video in iPad.

Resources