I am sharing audio file after getting it from iPhone Music Library. After successfully getting path of audio, I implemented following lines of code
dispatch_async(dispatch_get_main_queue(), ^{
if ( [self isWhatsAppInstalled] )
{
_docControll = [UIDocumentInteractionController interactionControllerWithURL:[NSURL fileURLWithPath:songPath]];
_docControll.UTI = #"net.whatsapp.audio";
_docControll.delegate = self;
[_docControll presentOpenInMenuFromRect:CGRectMake(0, 0, 0, 0) inView:view animated: YES];
} else {
[self alertWhatsappNotInstalled];
}
});
It opens dialogue in whatsapp to send audio, so I press to send and whatsapp shows progress that audio is sending, but meanwhile it fails.
Here is the path: "/var/mobile/Containers/Data/Application/9FE7FD43-6521-4E9E-A400-21C9FF03EE27/Documents/audio.waa"
I tried two formats of audio waa and mp3.
Audio successfully sent if it is being sent from Main Bundle.
Any Help will really be appretiated.
Blockquote
Related
I had tried to play video using vlckit for mac os x,
using below code but , i am unable to see video, after compiling i am having black screen but no video is playing.
here a.mp4 is my video inside main bundle , i had cheacked that videos path is correct.
let me know what is the issue why i am not able to see video on screen.
// Set up a videoView by hand. You can also do that in the nib file
videoView = [[VLCVideoView alloc] initWithFrame:NSMakeRect(0, 0, 400, 400)];
[self.view addSubview:videoView];
[videoView setAutoresizingMask: NSViewHeightSizable|NSViewWidthSizable];
// Init the player object
player = [[VLCMediaPlayer alloc] initWithVideoView:videoView];
[player setMedia:[VLCMedia mediaWithPath:#"/Users/gurpalrajput/Desktop/demoVlc Player/demoVlc Player/a.mp4"]];
[player play];
That path looks wrong; for a resource inside a macOS application I would expect something like /path/to/Application.app/Contents/Resources/a.mp4. You're not on iOS anymore... ;)
Generally you want to resolve paths to resources inside the application bundle programmatically; for the movie that would be:
NSString* path = [NSBundle.mainBundle pathForResource:#"a" ofType:#"mp4"];
Am using AVPlayer to play video. Video playing without any problem except iPad Pro. In iPad pro its getting stuck or delayed to start.
avPlayerViewController = [[AVPlayerViewController alloc]init];
avPlayerItem = [[AVPlayerItem alloc]initWithURL:fileURL];
player = [[AVPlayer alloc]initWithPlayerItem:avPlayerItem];
avPlayerViewController.player = player;
[avPlayerViewController.view setFrame:CGRectMake(0, 0, biManager.screenSize.width, biManager.screenSize.height)];
[self.view addSubview:avPlayerViewController.view];
avPlayerViewController.showsPlaybackControls = false ;
[player play];
I think the initWithURL is a sync call and may stop your UI. I went around it in my code by saving the video to a temp file and start the play only when the file was downloaded. Alternatively, you can try loadValuesAsynchronouslyForKeys:completionHandler: as suggested in this SO post. Also, there should be a way to stream videos with buffering. May be with third party's API like AFNetworking?
Hi guys ive been trying to find a way to mute and unmute (that is play audio) via Objective-C in-code, regardless of whether the app is in mute mode or not (physical mute toggled)
I see Instagram does that, where you can press the mute icon even if your phone is mute, and it will play video audio.
You want to look at audio session categories
With this code you can play audio when the Ring/Silent switch to silent.
NSError *setCategoryError = nil;
BOOL success = [[AVAudioSession sharedInstance]
setCategory: AVAudioSessionCategoryPlayback
error: &setCategoryError];
if (!success) { /* handle the error in setCategoryError */ }
I'm trying to embed a Youtube video using a mixture of this technique, and this Youtube SDK blog post in a universal app. The iPhone version, using the same code, works fine.
On the iPad the video does embed, and it plays fine in it's embedded form, but as soon as you tap the full screen button the app crashes (buttons do not respond, the device does not rotate). The music from the Youtube video keeps playing.
There is no error message logged but the app does register as 'Paused' or hung in xCode. Every time it crashes com.apple.libdispatch-manager is on thread 2. Ask me questions and I'll give you more information about the error, but I'm not sure where to start.
I have tried:
changing the size of the UIWebView frame
the UIWebView is in a UIScrollView, but if I take it out of the scrollview and add it to the view the problem is identical.
changing the video
changing the html that I use in the UIWebView from this to this, with no result
changing the format of the youtube link from ?v=uniqueID to /v/uniqueID
checking the presenting view is the rootviewcontroller (it is, but the video is embedded in a modal, which is not the rootviewcontroller).
I am building for iOS 5.1, this doesn't happen if running on iOS6.
The View that the video is embedded in is modal, both on the phone and the iPad. There's no hackery or unusual things happening in the app.
There seems to be talk of Evernote's app having a similar problem, but I don't know if it is related or not.
For your reference, here is the YouTubeView subclass (which subclasses UIWebView):
- (YouTubeView *)initWithStringAsURL:(NSString *)urlString frame:(CGRect)frame;
{
if (self = [super init])
{
// Create webview with requested frame size
self = [[YouTubeView alloc] initWithFrame:frame];
// HTML to embed YouTube video
// NSString *youTubeVideoHTML = #"<html><head>
// <body style=\"margin:0\">
// <embed id=\"yt\" src=\"%#\"
// type=\"application/x-shockwave-flash\"
// width=\"%0.0f\" height=\"%0.0f\">
// </embed>
// </body>
// </html>";
NSString *youTubeVideoHTML = #"<html><head><meta name = \"viewport\" content = \"initial-scale = 1.0, user-scalable = no, width = %0.0f\"/></head><body style=\"background:#FFF;margin-top:0px;margin-left:0px\"><div><object width=\"%0.0f\" height=\"%0.0f\"><param name=\"movie\" value=\"%#\"></param><param name=\"wmode\" value=\"transparent\"></param><embed src=\"%#\"type=\"application/x-shockwave-flash\" wmode=\"transparent\" width=\"%0.0f\" height=\"%0.0f\"></embed></object></div></body></html>";
// Populate HTML with the URL and requested frame size
// NSString *html = [NSString stringWithFormat:youTubeVideoHTML, urlString, frame.size.width, frame.size.height];
NSLog(#"html:\n %#", youTubeVideoHTML);
NSString *html = [NSString stringWithFormat:youTubeVideoHTML, frame.size.width, frame.size.width, frame.size.height, urlString, urlString, frame.size.width, frame.size.height];
NSLog(#"html:\n %#", html);
// Load the html into the webview
[self loadHTMLString:html baseURL:nil];
}
return self;
}
Modal view on iOS 5.0 and iOS 5.1 is the problem that causes crash on full screen video, AFAIK. They just changed hierarchy of views in that version of iOS (parentViewController and presentingViewController) and that is the aftermath. I asked about it long time ago here and one more same question is here and still no one knows what to do.
First of all, they fixed it in 6.0, I guess, that's good.
For 5.1 we changed design a little and avoided modal view. Do it, if it is possible in your situation.
I'm developing on iOS SDK 4.3.
I have an horizontally-scrolling paged gallery that can display images or videos from a remote feed. For the paged views I'm using the publicly available ATPagingView: pages are reused similarly to TableViewCells. But for the videos I'm using a single MPMoviePlayerController, whose .view property I assign to the several pages as a subview (I know, I know...):
moviePlayerController = [[MPMoviePlayerController alloc] init];
moviePlayerController.repeatMode = MPMovieRepeatModeNone;
moviePlayerController.controlStyle = MPMovieControlStyleEmbedded;
moviePlayerController.shouldAutoplay = false;
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(movieLoadStateChangeAction:) name:MPMoviePlayerLoadStateDidChangeNotification object:nil];
You can see I've registered for MoviePlayer event LoadState notifications.
When a new page goes onscreen, I start loading a video if needed:
- (void)currentPageDidChangeInPagingView:(ATPagingView *)pagingView
{
if (pagingView.currentPageIndex < 0)
return;
NSLog(#"currentPageDidChangeInPagingView");
GalleryPageView *currentPage = (GalleryPageView *)[pagingView viewForPageAtIndex:pagingView.currentPageIndex];
if (![currentPage.gestureRecognizers count]) {
UITapGestureRecognizer *recognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:#selector(resetZoom)];
recognizer.numberOfTapsRequired = 2;
[currentPage.zoomView addGestureRecognizer:recognizer];
recognizer.delegate = self;
[recognizer release];
}
moviePlayButton.hidden = YES;
[activityView stopAnimating];
FeedItem *feedItem = (FeedItem *)[dataRoot objectAtIndex:pagingView.currentPageIndex];
if (feedItem.contentType == FeedContentTypeMovie) {
moviePlayerController.contentURL = [NSURL URLWithString:feedItem.movieUrl];
[moviePlayerController prepareToPlay];
[activityView startAnimating];
}
Now, IFF the first page contains a video, even after I call moviePlayerController.prepareToPlay, it doesn't load: no loadState event is fired. Following pages instead work as expected.
I've tried to pre-load a fixed video on MPlayerController initialization, but in that case the fixed video is correctly loaded (MPMovieLoadState == 3), while video on first page causes a change to MPMovieLoadStateUnknown.
The movie URL is correct.
When I scroll back from page 2 to page 1, first video is loaded (MPMovieLoadState == 3), but it doesn't show.
What do you suggest investigating? Is the shared-view architecture so horrible? It works for the following pages, after all. Is there any known weird behavior by prepareToPlay? For example, is it possible MPC gets angry if the view is "mistreated" by anyone, and then it refuses to load stuff? How else would you explain MPMovieLoadStateUnknown? I'm pretty sure there is no other ghost instance of MPC messing around (I've read it could be a problem).
Thank you and sorry for the long post.
I had to end up using AVPlayer because of something very similar to this in my code.
I had the same problem. In iOS7 this does not happen, but in iOS 6 loadState is 3, which is not contemplated in:
enum {
MPMovieLoadStateUnknown = 0,
MPMovieLoadStatePlayable = 1 << 0,
MPMovieLoadStatePlaythroughOK = 1 << 1, // Playback will be automatically started in this state when shouldAutoplay is YES
MPMovieLoadStateStalled = 1 << 2, // Playback will be automatically paused in this state, if started
};
typedef NSInteger MPMovieLoadState;
I had autoplay set to NO and use prepareToPlay waiting for the notifications to play, so when MPMoviePlayerLoadStateDidChangeNotification is received, before playing, I check the loadState like this:
if (self.moviePlayerC.loadState & MPMovieLoadStatePlayable || self.moviePlayerC.loadState & MPMovieLoadStatePlaythroughOK)
Maybe in iOS6 loadState is a bitWise value that can contains several states at the same time.