I created an app for streaming audio (and send mail as well) but I have a problem, my app will not keep playing after I press the home button.
I use XCODE 6.4 and the mediaplayer.framework to play the stream it is in viewcontroller and I have been activating the background mode Audio & airplay.
Can someone please let me know what I am doing wrong here, I really want to learn it.
code:
NSURL *videoStreamURL = [NSURL URLWithString:#"http://streamlink.m3u"];
_player = [[MPMoviePlayerController alloc] initWithContentURL:videoStreamURL];
_player.view.frame = CGRectMake(0, 530, self.view.frame.size.width, 38);
[self.view addSubview:_player.view];
[_player play];
Related
I have and MPMoviePlayerController in my project. I tried to run it on iOS 8.0. When I play the video for the first time, It works fine and I have the progress bar of the video. Then I quit and try to play the video for the second time. It still works except than I don't have the progress bar of the video. I said in the title "setFullScreen:animated" because I also had the error "CGImageCreate : invalid image size 0x0" so I guess It can come frome here.
Also, it appears to work without any problem on iOS 8.1, so I think it's bug corrected by Apple. Maybe someone have heard something about it.
Here is some code when the Controller is created and setted :
_moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:
[NSURL fileURLWithPath:self.model.filePath]];
_moviePlayer.controlStyle = MPMovieControlStyleFullscreen;
_moviePlayer.view.backgroundColor = [UIColor blackColor];
_moviePlayer.view.frame = self.imageButton.frame;
[self.view addSubview:_moviePlayer.view];
[_moviePlayer setFullscreen:YES animated:YES];
[_moviePlayer prepareToPlay];
Any guess ?
I have the following code set up to play a video in my iOS app, but it just doesn't play. The app compiles and runs, but all I get a red frame where I positioned it. When debugging, I found that the the program doesn't even step into the last line [player play]. Also, the video runs fine in a UIWebView.
NSString *streamingString = [NSString stringWithFormat:#"http://youtu.be/...."];
AVAsset *asset = [AVAsset assetWithURL:[NSURL URLWithString:streamingString]];
AVPlayerItem *playerItem = [[AVPlayerItem alloc] initWithAsset:asset];
AVPlayer *player = [AVPlayer playerWithPlayerItem:playerItem];
AVPlayerLayer *layer = [AVPlayerLayer playerLayerWithPlayer:player];
[layer setPlayer:player];
[layer setFrame:CGRectMake(50, 50, 400, 300)];
[layer setBackgroundColor:[UIColor redColor].CGColor];
[layer setVideoGravity:AVLayerVideoGravityResizeAspectFill];
[self.view.layer addSublayer:layer];
[player play];
I am a new programmer and this is my first post to Stackoverflow, so please excuse me if I have not given enough information or am missing something obvious! Thank you so much!
assetWithURL: is often, but not always, used with a URL that points to a file already on the device, often within the bundle. If you are using an external URL, such as one on the internet, the url must resolve to a video that is in a format that the AVPlayer can understand. A URL to a YouTube web page will not work. In general, you can't play a YouTube video in AVPlayer.
Check out this document from Apple and this video on YouTube.
EDIT:
Some developers have used this library to play a YouTube video in their app. Another option is to use a UIWebView.
I am using the below code to play the video, but its working fine while using the local url that mean resourse file path. Not working for server url.
player = [[MPMoviePlayerViewController alloc] initWithContentURL:urlvalue];
player.view.frame = CGRectMake(10, 10, 800, 800);
player.moviePlayer.shouldAutoplay=YES;
player.moviePlayer.movieSourceType= MPMovieSourceTypeFile;
[player.moviePlayer setControlStyle:MPMovieControlStyleDefault];
[self.view addSubview:player.view];
[player.moviePlayer prepareToPlay];
[player.moviePlayer play];
Kindly correct me if I missed out something. Thanks in advance.
Pay attention on iOS 9 App transport security. If you haven't set it up, streaming will fail with black empty screen.
Change movieSourceType from File to Streaming :
player.moviePlayer.movieSourceType= MPMovieSourceTypeStreaming;
Note : url should be a streaming url not physical file path
I want to create an app which has a default image as the background of a view that has many buttons on it. When a user clicks on any of the buttons, a unique video plays. The buttons are gonna be almost transparent so, I want the video to play in the background of the same view itself (replacing/playing above the image) and not open in a new Player(as it does using the media player). Has anyone tried it, or does anyone have any idea?
Thank You!
#import <MediaPlayer/MPMoviePlayerController.h>
MPMoviePlayerController* moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL: [NSURL fileURLWithPath: moviePath]];
moviePlayer.controlStyle = MPMovieControlStyleNone;
[RootViewController.view insertSubview: moviePlayer.view aboveSubview: myView];
[moviePlayer play];
I use a MPMoviePlayerController to play audio (ex: http://www.stanford.edu/group/edcorner/uploads/podcast/ballmer090506.mp3) or video (ex: http://video.ted.com/talk/podcast/2011U/None/RicElias_2011U.mp4)
myMoviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:theURL];
myMoviePlayer.view.frame = CGRectMake(-80, 80, 480, 320);
myMoviePlayer.controlStyle = MPMovieControlStyleFullscreen;
myMoviePlayer.movieSourceType = MPMovieSourceTypeFile;
myMoviePlayer.scalingMode = MPMovieScalingModeAspectFit;
myMoviePlayer.useApplicationAudioSession = TRUE;
[myMoviePlayer prepareToPlay];
[myMoviePlayer play];
It works well, my only one problem is during the loading time (between 5s and 20s if I have a bad 3G reception), I have a black screen.
I would like to have MPMoviePlayerController diplayed with the "Loading..." label and the UIActiviyIndicator in his top bar during this time, like YouTube videos.
How can I do that?
Thanks.
Just use MPMoviePlayerViewController instead of MPMoviePlayerController. It should do what you want.