I wanna play mms protocol audio, any idea about this? I heard libmms is a choice. But i do not know how. Anyone can share sample codes? it's better introduce from scratch.
Thanks in advance!!!
You need to look into the DocumentInteractionController here: https://developer.apple.com/library/ios/documentation/FileManagement/Conceptual/DocumentInteraction_TopicsForIOS/DocumentInteraction_TopicsForIOS.pdf The Document Interaction Controller is the "Apple" way to do it and likely your safest path now and in future versions of the iOS.
If you own the file in your bundle you can get the default app to handle the file type from the OS:
NSString *filePath = [documentsDirectory stringByAppendingPathComponent: fileName];
if ([[NSFileManager defaultManager] fileExistsAtPath:[self getFileCompletePath]]){
NSString *filePath = [[NSString alloc] initWithFormat:#"%#", [self getFileCompletePath]];
NSURL *url = [[NSURL alloc] initFileURLWithPath:filePath];
if ([[UIApplication sharedApplication] canOpenURL:url]){
[[UIApplication sharedApplication] openURL: url];
} else {
NSLog(#"Not supported application to open the file %#", filePath);
}
[url release];
[filePath release];
}
Good Luck!
You basically have two options:
Libmms: this library will only handle the mms protocol. So it's up to you to do whatever you want with the data.
FFmpeg: this library can handle the mms protocol and also has audio/video decoding capabilities. Since you'll be using the mms:// protocol for audio/video streaming, choosing FFmpeg will be a better choice.
Related
I am trying to use Apple App Thinning feature (available from iOS 9) that let you differentiate resources based on device architecture and features. In my case what I would like to do is to have a different video file in the application bundle (in .mp4 format) one for the iPhone and one for the iPad using Xcode .xcassets Data Set.
To retrieve a file from a .xcassets Data Set Apple provides the NSDataAsset class, but: since AVPlayer needs a URL to play a video and NSDataAsset only provides its contents using Data format, I'm unable to play the video.
What I would like to do is to retrive the NSDataAsset .data URL. Is it possible?
You can try:
NSDataAsset *videosDataAsset = [[NSDataAsset alloc] initWithName:#"AssetName"];
NSData *data = videosDataAsset.data;
NSString *filename = #"FileToSaveInto.mp4";
NSURL *URL = [[[[NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask] lastObject] URLByAppendingPathComponent:filename];
if ([data writeToURL:URL atomically:YES]) {
// run player
}
I am new to Programing, I've programed an iOS app which is almost completed, Now I want to integrate contents(Image, Text and URL) sharing capability to my app, I've achieved Facebook and Twitter Sharing functionality, But I am stuck at Instagram sharing functionality since two days.
I've studied lots of material(earlier asked question here StackOverFlow, also tried MGInstagram and few other third party API's) but all of those are outdated & not working on iOS9 & iOS10,
I tried to achieve some help from Instagram site but there too I am not cleared.
Can Anyone Define some easy way to integrate Instagram Sharing button code in my iOS app also to define authentication process from Instagram site clearly like as tokens & other permissions required for developers.
Thanks
As per your Desired question for iOS 9 and 10 So I am explaining for both.
I am using Instagram,s Standard Documentation API as defined in iPhone Hooks at Instagram
Step1:
open your info.plist file and add LSApplicationQueriesSchemes and add your URL schemes which you are going to call in your canOpenURL like this.
It is also defined in WWDC 2015 Session 703 by kitty scatter.
<key>LSApplicationQueriesSchemes</key>
<array>
<string>instagram</string>
</array>
It will open instargram app installed in your device.
note It'll never work in your simulator because of unavailability of required app.
Step2:
in your .h file where your #interface line ends add this <UIDocumentInteractionControllerDelegate> to the same #interface line
Step3:
add following code for sharing image in your instagram sharing button's action
// This is your Image you want to share. you can write
UIImage *image = imageView.image;
//Add this line of code instead of doing step One if you are at early version of iOS9 till iOS 9.2.3 but if you are using iOS9.5 or above like as iOS10 not use this line and do step1 instead of writing this line of code
NSURL *instagram = [NSURL URLWithString:#"instagram://app"];
if ([[UIApplication sharedApplication] canOpenURL:instagram]) {
//convert image into .png format.
NSData *imageData = UIImagePNGRepresentation(image);
//create instance of NSFileManager
NSFileManager *fileManager = [NSFileManager defaultManager];
//create an array and store result of our search for the documents directory in it
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
//create NSString object, that holds our exact path to the documents directory
NSString *documentsDirectory = [paths objectAtIndex:0];
//add our image to the path
NSString *fullPath = [documentsDirectory stringByAppendingPathComponent:[NSString stringWithFormat:#"insta.igo"]];
//finally save the path (image)
[fileManager createFileAtPath:fullPath contents:imageData attributes:nil];
CGRect rect = CGRectMake(0 ,0 , 0, 0);
UIGraphicsBeginImageContextWithOptions(self.view.bounds.size, self.view.opaque, 0.0);
[self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIGraphicsEndImageContext();
NSString *fileNameToSave = [NSString stringWithFormat:#"Documents/insta.igo"];
NSString *jpgPath = [NSHomeDirectory() stringByAppendingPathComponent:fileNameToSave];
NSLog(#"jpg path %#",jpgPath);
NSString *newJpgPath = [NSString stringWithFormat:#"file://%#",jpgPath];
NSLog(#"with File path %#",newJpgPath);
// NSURL *igImageHookFile = [[NSURL alloc]initFileURLWithPath:newJpgPath];
NSURL *igImageHookFile = [NSURL URLWithString:newJpgPath];
NSLog(#"url Path %#",igImageHookFile);
UIDocumentInteractionController *documentController = [UIDocumentInteractionController interactionControllerWithURL:igImageHookFile];
documentController.delegate = self;
[documentController setUTI:#"com.instagram.exclusivegram"];
[documentController presentOpenInMenuFromRect:rect inView:self.view animated:YES];
} else {
// NSLog (#"Instagram not found");
UIAlertController* alert = [UIAlertController alertControllerWithTitle:#"Install Instagram"
message:#" Before Sharing to Instagram, Please Install Instagram app to your Device. "
preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction* defaultAction = [UIAlertAction actionWithTitle:#"Thanks" style:UIAlertActionStyleDefault
handler:nil];
[alert addAction:defaultAction];
[self presentViewController:alert animated:YES completion:nil];
}
Final Note:
Follow Step one if you are using iOS SDK 9.5 or above like 10. and to remove second line of code mentioned in third step. and in case you are using iOS 9 till 9.2.3 then no needs to do first step, you should follow second line of code of third step.
Hope it'll work smoothly like water flow. . . :)
This should open instagram on a device and share the photo onto Instagram.
- (IBAction)imageShareToInsta:(id)sender {
NSString *imagePath = [NSString stringWithFormat:#"%#/image.igo", [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)lastObject]];
[[NSFileManager defaultManager] removeItemAtPath:imagePath error:nil];
[UIImagePNGRepresentation(self.imageView.image) writeToFile:imagePath atomically:YES];
UIDocumentInteractionController *docController = [UIDocumentInteractionController interactionControllerWithURL:[NSURL fileURLWithPath:imagePath]];
docController.delegate=self;
docController.UTI = #"com.instagram.exclusivegram";
[docController presentOpenInMenuFromRect:self.view.frame inView:self.view animated:YES];
}
Declare <UIDocumentInteractionControllerDelegate>in your ViewController.h file
Hope it helps you out.
Sorry for bad Engilsh.
I am new to iOS development.And I am trying to create a client application which stream .m4a audio file from stream url
rtsp://192.168.1.50:1935/TestServer/abc.m4a
and play it on button click.
I have tried almost every thing which I can find but I was not able to get and play stream.
There is my code which play audio from http url
- (IBAction)btn:(id)sender {
NSString *str = #"http://download.wavetlan.com/SVV/Media/HTTP/AAC/Nero_Soundtrax/NeroSoundTrax_test1_AAC-LC_v4_Stereo_CBR_96kbps_44100Hz.m4a";
NSString *urlStr = [str stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
NSURL * mediaURL = [NSURL URLWithString:urlStr];
player = [AVPlayer playerWithURL:mediaURL];
[player play];
}
but I want to play audio file from this type of url. rtsp://192.168.1.50:1935/TestServer/abc.m4a
i tested my streaming url on VLC to verify. It works perfect but when I put that url on button click code it didn't work.
I try to use ffmpeg library but did not find luck in that.
Try register audio session category before playing.
- (IBAction)btn:(id)sender {
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback error:NULL];
NSString *str = #"http://download.wavetlan.com/SVV/Media/HTTP/AAC/Nero_Soundtrax/NeroSoundTrax_test1_AAC-LC_v4_Stereo_CBR_96kbps_44100Hz.m4a";
NSString *urlStr = [str stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
NSURL * mediaURL = [NSURL URLWithString:urlStr];
player = [AVPlayer playerWithURL:mediaURL];
[player play];
}
Hope this helps.
Standard iOS frameworks do not support RTSP playback, so you will have to use some third-party solution.
Hope this post helps:
https://gist.github.com/oc2pcoj/e55795550984d205d109
Summary (iOS 8, Xcode 6.4)
First question:- Can i share my app's Documents Directory's data with my other app?
If Yes, I've seen many questions related to this;
Move data/images between two iOS apps using custom URL handler,
http://code.tutsplus.com/tutorials/ios-sdk-working-with-url-schemes--mobile-6629
But I found that these example only send text or URLs. Then I tried myself as below:
NSString* path = [NSString stringWithFormat:#"MY_URL_SCHEME://"];
NSURL* url = [NSURL URLWithString:path];
if([[UIApplication sharedApplication]canOpenURL:url]) {
[[UIApplication sharedApplication]openURL:url];
}
The above code works well to open my other app. But when I try like below, I can't open my other app.
NSArray* mainPath = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *sourcePath = [mainPath objectAtIndex:0];
NSString* path = [NSString stringWithFormat:#"MY_URL_SCHEME://%#",sourcePath];
NSURL* url = [NSURL fileURLWithPath:path isDirectory:YES];
if([[UIApplication sharedApplication]canOpenURL:url]) {
[[UIApplication sharedApplication]openURL:url];
}
So, please help me, what am I missing?
EDIT:-
i forgot to mention that,iOS7 support is important in my App.so, i think extension might not work.
Use NSUserDefaults with app group to share the data between apps
NSUserDefaults *defaults=[[NSUserDefaults
alloc]initWithSuiteName:#"app group name"];
[defaults setObject:filedata forKey:#"keyfordata"];
[defaults synchronize];
in the app delegate of consuming app fetch the data from NSUserDefaults
another way is to use share extension-
http://easynativeextensions.com/how-to-launch-your-app-from-the-ios-8-share-menu/
You can refer MGInstagram files as Instagram mobile app works same. You can pass image from your application to Instagram application.
You can download it from here: https://github.com/mglagola/MGInstagram
Hope this helps.
I want to import data from my iPhone to my application . up till now i have successfully imported Photo Library and music , but i also want to import pdf and other documents in my iOS app? How can i do that?
NSString *bundlePath = [[NSBundle mainBundle] resourcePath];
NSFileManager *mgr = [[NSFileManager alloc] init];
NSArray *allFiles = [mgr contentsOfDirectoryAtPath:bundlePath error:NULL];
for (NSString *fileName in allFiles)
{
if ([[fileName pathExtension] isEqualToString:#"pdf"])
{
NSString *fullFilePath = [bundlePath stringByAppendingPathComponent:fileName];
// fullFilePath now contains the path to your pdf file
// DoSomethingWithFile(fullFilePath);
NSLog(#"file: %#",fullFilePath);
}
}
NSURL *url = [[NSBundle mainBundle] URLForResource:#"" withExtension: #"pdf"];
NSLog(#"File: %#",url);
You can't do it in iOS 8 (I haven't checked 9 though). You can't even enlist your app (adding corresponding URL schemes) in the sharing menu of iBooks.
You have to associate your app with the PDF types which you want to open. You can do this by adding some parameters to your Info.plist.
There's a well-answered post which explains this:
How do I associate file types with an iPhone application?
You should also consider reading Apple's documentation and a blog post written by me.