Stream audio with MPMoviePlayerController - ios

I'm trying play an audio stream from this site: http://www.radioteofilotoni.com.br/
I have:
MPMoviePlayerController *player = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL URLWithString:#"http://stream.jshost.com.br:1935/mobile/8056.stream/playlist.m3u8"]];
player.movieSourceType = MPMovieSourceTypeStreaming;
player.view.hidden = YES;
[self.view addSubview:player.view];
[player play];
Doesn't play anything, what's wrong? I can access this m3u8 link from Safari and play.
Thanks.

That URL doesn't return an audio stream-- it returns a text file that looks like this:
#EXTM3U
#EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=52855
http://stream.jshost.com.br:1935/mobile/8056.stream/playlist.m3u8?wowzasessionid=1884064341
Loading that URL gives some more non-audio content, which you can use to eventually get an audio stream URL. It looks like Mobile Safari parses the text files to get the stream URL. You'll have to do that, too, because apparently MPMoviePlayerController doesn't do it.

Related

AVPlayer - Detect action in default control player

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.

AVPlayer not loading video in iOS 8

AVPlayerViewController *playerViewController = [[AVPlayerViewController alloc] init];
playerViewController.player = [AVPlayer playerWithURL:[[NSBundle mainBundle]
URLForResource:#"Besan"
withExtension:#"mp4"]];
[playerViewController.player play];
I am trying to use the AVPlayerViewController in iOS 8. But the video does not load. I simply get the screen below.
The entire codebase is here https://github.com/sairamsankaran/AVPlayerDemo
I download your project and had a look. The solution is pretty simple, you forgot to include the video file in your target, which means when you're setting up the URL you're pointing to a file that doesn't exist, which means the NSURL is nil.
In the Utilities side bar in Xcode, with your mp4 file chosen in the navigator, choose the File Inspector and in "Target Membership" be sure to check your app target.
Once you have done this your movie will play on launch.
You might be better off starting with a working example and extending that. If you like, you can try a working xcode example project that uses AVPlayerViewController in github described in my blog post, this is an example project that shows a high def SDO video of the Sun, it looks best on a newish retina iPad since the video is very high quality.
#runmad, i also done with the same way,but i'm trying to open local video.here is my code
{
// Initialize the movie player view controller with a video URL string
AVPlayerViewController *playerViewController = [[AVPlayerViewController alloc] init];
/*NSURL *url = [NSURL URLWithString:#"https://www.youtube.com/watch?v=qcI2_v7Vj2U"];
playerViewController.player = [AVPlayer playerWithURL:url];*/
// playerViewController.player = [AVPlayer playerWithURL: [ [filePath]URLForResource:#"Besan"
// withExtension:#"mp4"]];
NSLog(#"\nFile URL\n%#",videosURL);
AVPlayerItem* item=[[AVPlayerItem alloc]initWithURL:videosURL];
NSLog(#"\n\nAVPlayerItem\n%#",item);
playerViewController.player=[AVPlayer playerWithPlayerItem:item];
[playerViewController.player play];
[self presentViewController:playerViewController animated:YES completion:^{}];
}
i've done without AVPlayerItem but the result is same(Only black screen with done,play,forward,backward buttons).
than i tried with MPMoviePlayerController but it dismissed soon without displaying video.
here is MPMoviePlayerController Code,
{
MPMoviePlayerViewController *moviePlayerController = [[MPMoviePlayerViewController alloc]initWithContentURL:videosURL];
[self presentMoviePlayerViewControllerAnimated:moviePlayerController];
[moviePlayerController.moviePlayer play];
}

NSUnknownKeyException in uiviewcontroller

I am trying to play a video file (m4v) from resource folder of my app (i.e local video). but I am not able to play the video. I referred apple's sample project for the MPMoviePlayer.
Also when i am giving background color to my movieplayercontroller object its appearing as its behind some black view and the black view ahead is showing that something is loading for few seconds but nothing get loaded and it results in black screen only.
Can someone help me out with it. please tell me what i am doing wrong.
Also, i have taken screenshot of the screen with problem so that you all can understand what i am trying to say but i dont know how to post it here. :(
NSString *urlString = [[NSBundle mainBundle] pathForResource:#"Movie" ofType:#"m4v"];
NSURL *urlObj = [NSURL fileURLWithPath:urlString];
UIGraphicsBeginImageContext(CGSizeMake(1,1));
MPMoviePlayerViewController *player = [[MPMoviePlayerViewController alloc] initWithContentURL:urlObj];
UIGraphicsEndImageContext();
[player.view setBounds:self.view.bounds];
// when playing from server source type shoud be MPMovieSourceTypeStreaming
[player.moviePlayer setMovieSourceType:MPMovieSourceTypeStreaming]; // I was missing this line therefore video was not playing
[player.moviePlayer setScalingMode:MPMovieScalingModeAspectFill];
[self.view addSubview:player.view];
[player.moviePlayer play];

Unable to retrieve Shoutcast .pls stream

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];

Using MPMoviePlayerViewController in SDK 3.2 for iPad

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...

Resources