I am struggling to find answers, for a seemingly fairly straightforward problem, and wondering if anyone could provide insights. The code below is a very basic code for playing an mp4 file when hitting a button.
@IBAction func playVideo(_ sender: UIButton) {
let bundleUrls = Bundle.main.urls(forResourcesWithExtension: "mp4", subdirectory: nil)!
let player = AVPlayer(url: bundleUrls[0])
let controller = AVPlayerViewController()
controller.player = player
present(controller, animated: true) {
player.play()
}
}
My problem is, with this code, I can play some files but can't certain files.
When I print AssetTrack.formatDescriptions, I've noticed a few differences between the two.
a file I can play
[<CMVideoFormatDescription 0x2809123d0 [0x205d20660]> {
mediaType:'vide'
mediaSubType:'avc1'
mediaSpecific: { codecType: 'avc1' dimensions: 1920 x 1080 }
extensions: {{ CVFieldCount = 1;
CVImageBufferChromaLocationBottomField = Left;
CVImageBufferChromaLocationTopField = Left;
CVImageBufferColorPrimaries = "ITU_R_709_2";
CVImageBufferTransferFunction = "ITU_R_709_2";
CVImageBufferYCbCrMatrix = "ITU_R_709_2";
Depth = 24;
FormatName = "AVC Coding";
FullRangeVideo = 0;
RevisionLevel = 0;
SampleDescriptionExtensionAtoms = {
avcC = {length = 39, bytes = 0x014d4029 ffe10018 674d4029 965200f0 ... 21010004 68eb7352 };
};
SpatialQuality = 0;
TemporalQuality = 0;
VerbatimISOSampleEntry = {length = 133, bytes = 0x00000085 61766331 00000000 00000001 ... 21010004 68eb7352 };
Version = 0; }} }]
a file I can't play
[<CMVideoFormatDescription 0x2835623a0 [0x205d20660]> {
mediaType:'vide'
mediaSubType:'avc1'
mediaSpecific: { codecType:
'avc1' dimensions: 1920 x 1080 }
extensions: {{
CVImageBufferChromaLocationBottomField = Left;
CVImageBufferChromaLocationTopField = Left;
CVImageBufferColorPrimaries = "ITU_R_709_2";
CVImageBufferTransferFunction = "ITU_R_709_2";
CVImageBufferYCbCrMatrix = "ITU_R_709_2";
CVPixelAspectRatio = {
HorizontalSpacing = 1;
VerticalSpacing = 1;
};
Depth = 24;
FormatName = "AVC Coding";
FullRangeVideo = 0;
RevisionLevel = 0;
SampleDescriptionExtensionAtoms = {
avcC = {length = 65, bytes = 0x01640029 ffe1002d 67640029 ac2ca401 ... e98d3525 fdf8f800 };
};
SpatialQuality = 0;
TemporalQuality = 0;
VerbatimISOSampleEntry = {length = 159, bytes = 0x0000009f 61766331 00000000 00000001 ... e98d3525 fdf8f800 };
Version = 0; }} }]
So,,, it seems the differences are:
The file I can play has "CVFieldCount = 1;"
The file I can't play has "CVPixelAspectRatio = {
HorizontalSpacing = 1;
VerticalSpacing = 1;
};"
Does anyone know how I will be able to play the file I can't play at the moment?
Thanks in advance!
User contributions licensed under CC BY-SA 3.0