Play video in iPhone using HTML5 and UIWebView - iphone

I am writing a small POC to play the video in iPhone app. I would like to do so in UIWebView with the help of HTML5. I dont want to use standard players like AVPlayer or MPMoviePlayerController.
Can someone throw some light on it?..
I am new to this HTML5 environment on iPhone. So, any help to start this POC would be appriciated.
I forget to add that i would like to play h264 live stream on server.
Thanks in advance.

Yes, you can do that:
NSString *bundleDirectory = [[NSBundle mainBundle] pathForResource:#"mov" ofType:nil];
NSString *filePath = [bundleDirectory stringByAppendingPathComponent:#"loopvideo.html"];
NSString *HTMLData = [NSString stringWithContentsOfFile:filePath encoding:NSUTF8StringEncoding error:nil];
[self.web loadHTMLString:HTMLData baseURL:[NSURL fileURLWithPath:bundleDirectory]];
In your HTML, you can embed the <video> tag and it should play.

Related

Creating a sound in iOS

I am using the following that I pulled out of a tutorial to help me play a quick sound in my game, but I will be using this very often to play sounds. Should I be doing anything different? or is this a proper way to play a sound effect.
NSString *path = [[NSBundle mainBundle] pathForResource:#"Sound/Microwave_Bell_Ding" ofType:#"mp3"];
NSURL *pathURL = [NSURL fileURLWithPath:path];
AudioServicesCreateSystemSoundID((CFURLRef) pathURL, &soundID);
AudioServicesPlaySystemSound(soundID);
Thanks!
first,you can't play mp3 in this way.second,you can store soundID,when you play next time,just call AudioServicesPlaySystemSound(soundID);

AVAudioPlayer. Optional redirect of audio files. In _audio i am getting null

I have debug this code in url I am getting the "fileName" string, which i want. But in _audio i am getting null.
I am using an AVAudioPlayer to play and stream audio files. I am playing audio files from resources and document directory, but if they are absent in document directory then I want to play that specific audio from it's url. By streaming and buffering it. Here is my code:
NSString *fileName = #"http://ilm.coeus-solutions.de/frontend/images/audios/mp3test.mp3";
fileName = [fileName stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSURL *url = [[NSURL alloc] initWithString:fileName];
AVAudioPlayer *_audio = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:nil];
You can try following code,
NSData *filelocation=[[NSData alloc]initWithContentsOfURL:[NSURL URLWithString:#"http://ilm.coeus-solutions.de/frontend/images/audios/mp3test.mp3"]];
MyAudioPlayer = [[AVAudioPlayer alloc]initWithData:filelocation error:nil];
hope this will solve your problem
Slam dear! Please read again my question I have just asked about audio streaming rather than downloading it and then playing it.
This below link helped me. By the way thanks all who try to help me.
http://cocoawithlove.com/2008/09/streaming-and-playing-live-mp3-stream.html
Thanks!

How to play videos from a URL into an iphone app with buffering?

I have an iphone app which requires the videos to be played from the URL.
I dont want to download the whole videos just as it eventually slows down my app.
I want to play the videos in a way that it buffers in between and then plays.
How to play videos from a URL into an iphone app with buffering?
Try Like this....
NSString *url = #"www.youtube.com/xyz";
NSString *htmlString =[NSString stringWithFormat:#"<object width='212' height='172'><param name='movie' value='%#'></param><param name='wmode' value='transparent'></param><embed src='%#'type='application/x-shockwave-flash' wmode='transparent' width='980' height='965'></embed></object>",url,url];
[myWebview loadHTMLString:htmlString baseURL:nil];
do you have own server for streaming?
then,
NSURL *url = [NSURL URLWithString: #"http://STREAMING URL"];
[myMPMoviePlayerController setContentURL: url];
[myMPMoviePlayerController play];

How to upload a Video in iPhone SDK

I want to upload a video to webserver. I can upload the video but the problem is how should i pick a video. Means I know there is a default UIImagePickerController that i can use to pick image, is there any thing similar to pick movies in iPhone?
Hope you are getting my problem.
Thanks
Check out this SO entry. It has a similar discussion.
NSString *path = [[NSBundle mainBundle] pathForResource:#"ddd" ofType:#"avi"];
NSData *data = [NSData dataWithContentsOfFile:path];
Assets library is another option that you can fetch all photos and videos programaticaly but in that you case you have to make your own pickerviewcontroller .
Use AVFoundation to capture video and upload it using MKNetworkKit.

What's the SIMPLEST way to play a sound clip in an iPhone app?

I want to be able to play a sound clip in an iPhone OS app. I've seen info on both NSSound as well as AVFoundation as being means for getting sound clips played on an iPhone OS device, but I'm still not clear on the subject and could use some help. No need to spell it out for me step-by-step in actual code, but if someone could give me a hint as to the general direction (i.e. which classes I should be focusing on) in which I should start moving I'll fill in the blanks myself. So, what's the SIMPLEST way to play a sound clip in an iPhone app?
Apple has an article on this subject, see: this link
AVAudioPlayer is the simplest way to play sounds of any length, looping or not, however it requires iPhone OS 2.2 or higher. A simple example:
NSString *soundFilePath =
[[NSBundle mainBundle] pathForResource: #"sound"
ofType: #"wav"];
NSURL *fileURL = [[NSURL alloc] initFileURLWithPath: soundFilePath];
AVAudioPlayer *newPlayer =
[[AVAudioPlayer alloc] initWithContentsOfURL: fileURL
error: nil];
[fileURL release];
[newPlayer play];
[newPlayer release];
It will play virtually any file format (aiff,wav,mp3,aac) Keep in mind that you can only play one mp3/aac file at a time.
Here's the simplest way I know of:
Convert your sound file to caf (use afconvert commandline tool) and add to your project.
caf stands for Core Audio Format (I think...)
Look for SoundEffect.h and .m in Apple's sample code. I believe both Metronome and BubbleLevel have it.
Copy to your project
Write code like below:
SoundEffect *SimpleSound = [[SoundEffect alloc] initWithContentsOfFile:[mainBundle pathForResource:#"soundfile" ofType:#"caf"]];
[SimpleSound play];
[SimpleSound release];
Study SoundEffect.m to get an idea of simple sound handling.