Inserting slowMo AVComposition into AVMutableComposition - ios

PHPhotoLibrary gives an AVComposition rather than an AVURLAsset for a video recorded in SlowMo. I want to insert slowMo videos into another AVMutableComposition, so this means I need to insert this AVComposition into AVMutableComposition which is my editing timeline. The hack I used before was to load the tracks and segments and find the mediaURL of asset.
AVCompositionTrack *track = [avAsset tracks][0];
AVCompositionTrackSegment *segment = track.segments[0];
mediaURL = [segment sourceURL];
Once I had mediaURL, I was able to create a new AVAsset that could be inserted into AVMutableComposition. But I wonder if there is a cleaner approach that allows the slowMo video composition to be directly inserted into the timeline AVMutableComposition?

Related

what is the best way to play and setup controls for video (like play, pause, stop, volume and seek bar) on xamarin.ios

what is the best way to play and set up controls for video (like play, pause, stop, volume and seek bar) on xamarin.ios.
Actually , there are lots of solutions which can implement it . Like MPMoviePlayerController,MPMoviePlayerViewController,AVPlayer,AVPlayerViewController...
Note: MPMoviePlayerController and MPMoviePlayerViewController are obsolete after iOS 9.0 .
The following code are the basic usage of AVPlayer
in the method ViewDidLoad
//Set the local movie file path
//string moviePath = NSBundle.MainBundle.PathForResource("xxx", "mp4");
//NSUrl movieUrl = NSUrl.FromFilename(moviePath);
//set remote url path
NSUrl movieUrl = new NSUrl("https://www.learningcontainer.com/wp-content/uploads/2020/05/sample-mp4-file.mp4");
//Using AVPlayer(using AVFoundation)
AVPlayer avPlayer;
AVPlayerLayer playerLayer;
AVAsset asset;
AVPlayerItem playerItem;
asset = AVAsset.FromUrl(movieUrl);
playerItem = new AVPlayerItem(asset);
avPlayer = new AVPlayer(playerItem);
playerLayer = AVPlayerLayer.FromPlayer(avPlayer);
playerLayer.Frame = new CGRect(50, 300, 200, 200);
View.Layer.AddSublayer(playerLayer);
avPlayer.Play();
// you can add button and slider to control the play, pause , seek and volume
avPlayer.Pause();
avPlayer.Seek();
avPlayer.Volume = xxx;
In this way , you need to define the UI of Control Element by yourself.
If the url is always remote , we can also open the url in WKWebView . It had implemented pause and seek function in default .
//set remote url path
NSUrl movieUrl = new NSUrl("https://www.learningcontainer.com/wp-content/uploads/2020/05/sample-mp4-file.mp4");
var webView = new WKWebView(View.Frame, new WKWebViewConfiguration());
Add(webView);
using (var request = NSUrlRequest.FromUrl(movieUrl))
{
webView.LoadRequest(request);
}

Get album artwork from song playing through Apple Music

I am testing my app with Apple Music, my app grabs the current playing song and displays relevant information on it.
One of the steps is to get the album artwork, however I find that when the song is playing from Apple Music it does not contain any artwork.
Here is my code, the first if condition is ran, which suggests that the artwork is initialized, however I get no image.
Does anyone know how I can get the artwork when the song is being played though Apple Music?
song is of type MPMediaItem
CGSize artworkImageViewSize = cell.albumImage.bounds.size;
MPMediaItemArtwork *artwork = [song valueForProperty:MPMediaItemPropertyArtwork];
if (artwork)
{
cell.albumImage.image = [artwork imageWithSize:artworkImageViewSize];
}
else
{
cell.albumImage.image = [UIImage imageNamed:#"noArtwork"];
}
Whenever I try to print artwork.bounds I get back null.

audio slow motion like default Slo-Mo Camera functionality using 240FPS

i want to implement Slowmotion Video like Defalut functionality of Slo-Mo in Camera and i used following code and it worked fine for video.
but in Audio track of that video is not working properly.
double videoScaleFactor =8.0;
compositionAudioTrack scaleTimeRange:CMTimeRangeMake(kCMTimeZero, videoDuration)
toDuration:CMTimeMake(videoDuration.value* videoScaleFactor,videoDuration.timescale)];
[compositionVideoTrack scaleTimeRange:CMTimeRangeMake(kCMTimeZero, videoDuration)
toDuration:CMTimeMake(videoDuration.value* videoScaleFactor, videoDuration.timescale)];
this scenario is woking properly for video slowmotion.But in audio slow-motion it is not working...
Please help me..
i found solution of Audio SlowMotion
double videoScaleFactor =8.0;
[compositionAudioTrack scaleTimeRange:CMTimeRangeMake(kCMTimeZero, videoDuration)
toDuration:CMTimeMake(videoDuration.value* videoScaleFactor,videoDuration.timescale)];
its working properly but not working in AVPlayer
so for that you have to set following property of AVPlayerItem
AVPlayerItem *playerItem = nil;
playerItem.audioTimePitchAlgorithm = AVAudioTimePitchAlgorithmVarispeed;

Can we know the naturalSize of a video directly from the file?

I need the information about naturalSize of the video without playing it in the moviePlayer as my ViewController loads.
I have the file in the device and I know its path I just need to know its naturalSize.
You can, you have to create an AVAsset first and then check its natural size property, here is a reference...and here is an example
AVAsset *asset = [AVAsset assetWithUrl:..];
CGSize s= asset.naturalSize
hope it helps

How to reset the content URL for MPMoviePlayerController when playing a video?

I want to reset the content URL for the MPMoviePlayerController object when playing a video.
on a button click, I am setting the content URL like below,
[videoPlayer setContentURL:url];
But i am getting the "Bad Access" error.
Is there a way to change the url when a movie player is already playing a video?
It should stop the previous video and should start the video for the new url.
It means you didn't allocate memory to videoplayer
MPMoviePlayerController * videoplayer = [MPMoviePlayerController alloc] init];
[videoplayer setcontenturl: url];
it will not give you any error.

Resources