我目前在我的iOS應用程序中使用rtmpdump
作爲C程序。但是,我似乎無需重新啓動應用程序就可以多次使用它。這可能是什麼原因,我該如何解決它?發佈C庫(使用ARC)
相關代碼:
NSDictionary *details = [args objectAtIndex:0]; //rtmpe deatils
NSString *flvStore = [args objectAtIndex:1];
NSString *mp4Store = [args objectAtIndex:2];
[self performSelectorOnMainThread:@selector(updateProgressBar:) withObject:flvPath waitUntilDone:NO];
[self getFlashFile:details withFlvPathName:flvStore];
NSFileManager *fileManager = [NSFileManager defaultManager];
if([fileManager fileExistsAtPath:flvPath]){
NSNumber *filesize = 0;
NSDictionary *fileAttributes = [[NSFileManager defaultManager] fileAttributesAtPath:flvPath traverseLink:NO];
if(fileAttributes != nil){
filesize = [fileAttributes objectForKey:NSFileSize];
}
if([filesize longLongValue] > 1024){
[self removeFlvWrapper:flvPath withMp4PathName:mp4Path andTitle:[thePid objectForKey:@"title"]];
}
[fileManager removeItemAtPath:flvPath error:NULL];
}
- (void)getFlashFile:(NSDictionary *)details withFlvPathName:(NSString *)flvPath {
static char **rt_argv;
static int rt_argc;
rt_argc = 16;
rt_argv = (char **)malloc(sizeof(char *) * (rt_argc));
rt_argv[0] = "rtmpdump";
rt_argv[1] = (char *)[@"-r" UTF8String];
rt_argv[2] = (char *)[[details objectForKey:@"r"] UTF8String];
rt_argv[3] = (char *)[@"-a" UTF8String];
rt_argv[4] = (char *)[[details objectForKey:@"a"] UTF8String];
rt_argv[5] = (char *)[@"-f" UTF8String];
rt_argv[6] = (char *)[@"WIN 10,0,32,18" UTF8String];
rt_argv[7] = (char *)[@"-W" UTF8String];
rt_argv[8] = (char *)[[details objectForKey:@"W"] UTF8String];
rt_argv[9] = (char *)[@"-p" UTF8String];
rt_argv[10] = (char *)[[details objectForKey:@"p"] UTF8String];
rt_argv[11] = (char *)[@"-y" UTF8String];
rt_argv[12] = (char *)[[details objectForKey:@"y"] UTF8String];
rt_argv[13] = (char *)[@"-o" UTF8String];
rt_argv[14] = (char *)[flvPath UTF8String];
rt_argv[15] = (char *)[@"-q" UTF8String];
getStream(rt_argc, rt_argv);
finished = true;
}
您也可以看看BigBadOwl repository under iPlayerFetch.m看到類似的代碼。
請勿再使用[[@「foo」UTF8String]'! C也有不變的字符串。 '「foo」'很好。 – 2013-02-12 18:05:22
如果您嘗試做兩次會出現什麼問題?爲什麼你不能再次使用它? – 2013-02-12 18:16:32
我不確定...這兩種方法都在一個名爲DMDownloader的獨立類中,每當用戶點擊一個表格單元格時都會創建它。我可以確認下載在用戶界面掛在getFlashFile上時可以正常工作。但是,第二次用戶單擊單元格時,UI不會掛起,臨時文件(flv)不會在臨時目錄中創建,因爲這是第一次。 – 2013-02-13 03:41:21