Hi I'm using XCDYouTubeVideoPlayer to play the youtube video inside my app everything works fine. The problem is after navigating to next VC video is still playing how to pause or stop that video.
My code to play .
UIView *videoContainerView = [[UIView alloc]initWithFrame:CGRectMake(0, 200, 320, 200)];
[self.view addSubview:videoContainerView];
XCDYouTubeVideoPlayerViewController *videoPlayerViewController = [[XCDYouTubeVideoPlayerViewController alloc] initWithVideoIdentifier:vd];
// NSLog(#"%#",inVideosObj.video);
[videoPlayerViewController presentInView:videoContainerView];
[videoPlayerViewController.moviePlayer play];
My code to pause.
XCDYouTubeVideoPlayerViewController *videoPlayerViewController = [[XCDYouTubeVideoPlayerViewController alloc] initWithVideoIdentifier:vd];
[videoPlayerViewController.moviePlayer pause];
I have used this above code to pause the video its not working please help me i have been stuck here for long time .
Thanks.
You are creating a new instance of XCDYouTubeVideoPlayerViewController. Instead, you should store your XCDYouTubeVideoPlayerViewController instance in a property when you first create it and use this one when you need to stop the video. See DemoInlineViewController.m from the demo project for a concrete example.
Related
I use AVPlayer by default, not custom control.
AVPlayer *player = [AVPlayer playerWithURL:[NSURL URLWithString:#"https://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4"]];
AVPlayerViewController *avPlayerVC = [[AVPlayerViewController alloc] init];
avPlayerVC.player = player;
avPlayerVC.view.translatesAutoresizingMaskIntoConstraints = NO;
[self addChildViewController:avPlayerVC];
[self.view addSubview:avPlayerVC.view];
[player play];
... (auto layout here)
AVPlayer works normally but I can't handle any event from it.
When a user clicks on the previous or next button, I want to be able to detect or receive events to update other URLs. When I try it myself, it does not work.
I tried to use AVQueuePlayer with 3 URLs, but the video only changes the URL when it finishes the current item, the 2 buttons next/previous doesn't work.
I want to receive event on control avplayer, How do I do this? Thank so much! Sorry for my bad English.
Actually i am using MPMoviePlayerViewController in our app . And my code perfectly working in iOS 8.4 but when i upload my app into iPad (iOS 9 ) its not working ...
I am create ViewController to play two video one by one but when one video is completed or stop the controller going to my first page of app and behave unespected in iOS 9 .I am using custom MPMoviePlayerViewController to play video and put one button on first video to change other video but its not working...
NSURL *URL = [[NSBundle mainBundle] URLForResource:#"video" withExtension:#"mp4"];
self.indiaplayer = [[MPMoviePlayerController alloc] initWithContentURL:URL];
self.indiaplayer.view.frame = CGRectMake(0, 0,1024,718);
[self.indiavideoThumbnail addSubview: self.indiaplayer.view];
self.indiaplayer.controlStyle = MPMovieControlStyleNone;
self.indiaplayer.fullscreen = YES;
self.indiaplayer.repeatMode = YES;
[self.indiaplayer prepareToPlay];
self.indiaplayer.shouldAutoplay = NO;
self.indiaplaybackView = [[UIView alloc] initWithFrame:CGRectZero];
self.indiaplaybackView.backgroundColor = [UIColor colorWithRed:242.0/255 green:163.0/255 blue:10.0/255 alpha:1];
//self.playbackView.layer.cornerRadius = 2;
[indiaView addSubview:self.indiaplaybackView];
self.indiaslider.minimumValue = START;
self.indiaslider.maximumValue = END;
Thanks in advance
wait wait in iOS 9.x.x
IMPORTANT
The MPMoviePlayerViewController class is formally deprecated in iOS 9. (The MPMoviePlayerController class is also formally deprecated.) To play video content in iOS 9 and later, instead use the AVPictureInPictureController or AVPlayerViewController class from the AVKit framework, or the WKWebView class from WebKit.
For more detail
https://developer.apple.com/library/ios/documentation/MediaPlayer/Reference/MPMoviePlayerViewController_class/
I am using a CDLongAudioSource to play my music in my cocos2d game. But the issue is my game crashes some time when my audio file only loads but not play because I go back from my scene to other then if I come again in my scene where audio file need to play app crash.
Function to play file:
-(void)playMyEffect:(NSString*)audioFile{
CDLongAudioSource*currentSound = [[CDAudioManager sharedManager] audioSourceForChannel:kASC_Right];
//[currentSound load:#""];
NSLog(#" file path to play %#",audioFile);
[currentSound load:audioFile];
currentSound.delegate = self;
currentSound.backgroundMusic = NO;
self.isSpeechComplete = NO;
[currentSound play];
}
Make sure you stop the player, and remove memory reference before navigating to other scene. I think this should work.
I'm trying to get a .pls stream from a shoutcast server to play in my ios app. So far i've been unsuccessful. I've red a lot of posts on stackoverflow but non of these were of any help.
Can anyone please explain to me, if its even possible, how to get .pls to stream?
all you need is to list the port of you radio, here is one working example:
in - (void)viewDidLoad
NSURL *vibes = [NSURL URLWithString:#"http://website.com:8002"];
vPlayer = [[AVPlayer alloc] initWithURL:vibes];
self.myViewVolume = [[MPVolumeView alloc] initWithFrame:CGRectMake(20, 330, 280, 50)];
[self.myViewVolume sizeToFit];
[self.view addSubview:self.myViewVolume];
you need to create an instance of AVPlayer in your .m file , here it is vPlayer
do not forget to add AVFoundation framework to you project, you can play and stop the stream with [player play] and [player stop]
One problem with AVPlayer is the lack of easy volume control, you can add one with mpViewVolume.
I am also working on radio app and by far AVPlayer is the best to play shoutcast streams.
#Walid Hussain
it worked for me using AVPlayer
link with AVFoundation.framework
//import needed
#import <AVFoundation/AVFoundation.h>
// declaration for the player
AVPlayer * radioPlayer;
// play
NSURL * url = [NSURL URLWithString:#"http://energy10.egihosting.com:9636"];
radioPlayer = [[AVPlayer playerWithURL:url] retain];
[radioPlayer play];
I've developed an iPhone app that has been running MPMoviePlayer (pre 3.2 SDK) with no problems. I know this is a newbie question, but how do I get a movie to play in the new MPMoviePlayerViewController. I am only getting audio and wish to learn the new view controller. I've ported my whole app over to iPad and everything else works fine except for video. Could someone please show an example using the movie view controller? Any help would be appreciated.
Thanks,
NSURL* videoURL = [NSURL URLWithString:url];
MPMoviePlayerController moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:videoURL];
[moviePlayer prepareToPlay];
[moviePlayer play];
//For viewing partially.....
[moviePlayer.view setFrame:CGRectMake(50, 200, (self.view.frame.size.width)-100 , 400)];
moviePlayer.view.backgroundColor = [UIColor grayColor];
[self.view addSubview:moviePlayer.view];
You need to use MPMoviePlayerViewController, not MPMoviePlayerController. Search the docs for MPMoviePlayerViewController.
Try this in your view controller:
MPMoviePlayerViewController* theMoviePlayer = [[MPMoviePlayerViewController alloc] initWithContentURL:videoURL];
[self presentMoviePlayerViewControllerAnimated:theMoviePlayer];
This should get you started but check the MPMoviePlayerViewController Class Reference for detailed info.
I've struggled all over the place with this - Apple's own MoviePlayer sample code doesn't play video, only audio. It actually took me ages to figure out that it was playing audio because the sample airplane video they supply has NO AUDIO TRACK!!! (So I click the button and get absolutely nothing.)
Thanks for all the suggestions here. I finally found https://developer.apple.com/library/ios/#qa/qa2010/qa1240.html
and even that is an obscure-ish fix.
This works: in initAndPlayMovie after [mp release]:
[[self.moviePlayer view] setFrame:[window bounds]];// size to fit parent view exactly
[window addSubview:[self.moviePlayer view]];
Bon voyage and happy flying :)
change this line:
MPMoviePlayerController moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:videoURL];
to
MPMoviePlayerController *moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:videoURL];
you need the *
I am pretty sure that its broken in simulator at present ! I get same behavior (no video but hear audio) with latest sdk and their own MPMoviePlayer sample code with Apples own video that Will play in iPad simulator using safari... So bottom line video plays on simulator-ipad inside of Safari but Not from an app using MpMoviePlayer class. Bug or feature, you decide. (I think its just broken). release notes for this version have lots of changes going on in MPMoviePlayer class...