Ios 如何在swift中将mp4文件的前两位更改为00,00?
我正在尝试将mp4文件的前两位更改为00,00以将其更改回正常/工作状态。从API下载mp4文件后,我发现它无法播放,而且行为怪异,因此在互联网上我发现有人说它是编码的,将前两位更改为0使其工作!(是的,但是)我不知道如何在swift中做到这一点。任何帮助都将不胜感激 我知道怎么做了!代码如下:Ios 如何在swift中将mp4文件的前两位更改为00,00?,ios,swift,xcode,watchkit,bit,Ios,Swift,Xcode,Watchkit,Bit,我正在尝试将mp4文件的前两位更改为00,00以将其更改回正常/工作状态。从API下载mp4文件后,我发现它无法播放,而且行为怪异,因此在互联网上我发现有人说它是编码的,将前两位更改为0使其工作!(是的,但是)我不知道如何在swift中做到这一点。任何帮助都将不胜感激 我知道怎么做了!代码如下: import UIKit import AVFoundation // URL to a mp4 file called videoFile located in the project's fo
import UIKit
import AVFoundation
// URL to a mp4 file called videoFile located in the project's folder:
let videoURL = URL(string: Bundle.main.path(forResource: "videoFile", ofType: "mp4")!)
// Func for "decoding" (changing it's 2 first bytes to 0):
func changeFirstTwoBytesOfFile(fileURL: URL) {
var fileData = fileURL.dataRepresentation
// Printing first 4 bytes of the unchanged file for checking:
print("Bytes before change:")
print(fileData[0])
print(fileData[1])
print(fileData[2])
print(fileData[3])
print("")
print("")
// Changing it's 2 first bytes to 0
fileData[0] = 0
fileData[1] = 0
// Printing the changed file's bytes to check if the change took place:
print("Bytes after change:")
print(fileData[0])
print(fileData[1])
print(fileData[2])
print(fileData[3])
}
changeFirstTwoBytesOfFile(fileURL: videoURL!)
你有什么样的数据结构来保存字节?要更改前两位还是前两个字节?如果是位,您是指字节的最高有效位吗
0bxx000000
对不起,我不能100%确定我使用了这个工具:hexed.it/?hl=pl要使文件在swift之外工作,我想我需要更改字节以更具体!