所以我正在尝试播放一个简单的介绍动画视频文件,我已将其拖入XCode中的项目中,因此应该可以从我的mainBundle播放,对吧?
使用此代码:
NSURL *urlString = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"introvideo" ofType:@"mp4"]];
MPMoviePlayerController *player = [[MPMoviePlayerController alloc] initWithContentURL:urlString];
[player play];
Run Code Online (Sandbox Code Playgroud)
我收到此错误消息: *由于未捕获的异常'NSInvalidArgumentException'终止应用程序,原因:'* - [NSURL initFileURLWithPath:]:nil string parameter'
任何帮助都会很棒!
我的主要包中包含文件夹,我想在首次启动应用程序时将它们复制/剪切到文档目录,以便从那里访问它们.我见过一些例子,但他们都在Obj-C中,我正在使用Swift 3.我怎么能这样做?
我有很多jpeg + png + html文件要添加到我的应用程序中,当然,当我"构建"它时,我的所有资源文件都添加/包含在myApp mainBundle文件夹中.
我希望能够在运行时通过代码修改我的一些资源,但是:
1)我们不能在mainBundle的运行时通过代码"编写"文件
2)我们可以只在"文档"文件夹(或临时,或...)中执行此操作
3)我们可以在运行时通过代码复制"Documents"文件夹中的文件
4)在"文档"中处理后,我们无法删除mainBundle文件
但这意味着我们的应用程序会增加一倍,在大型应用程序中(这是我的情况)这应该是无意义的,我们将在mainBundle中再次使用大量的大文件...
所以我想知道是否有解决这个问题的方法(只是我认为这是无意义的吗?)通过xCode或其他类似解决方案直接在"构建"阶段的"Documents"文件夹中添加文件. ..
PS
一个可能是用户第一次通过服务器/互联网直接在"Documents"文件夹中下载所有文件,所以我的应用程序不会很难通过iTunesStore下载,但当然这将花费大量时间最终用户的第一次,当然,它可能不被广泛接受......
我有一个我用MonoTouch编写的应用程序.我将名为ARCSDev的文件放入application文件夹并将其包含在项目中,然后我尝试使用以下代码读入该文件:
private void generateChart (int chartNumber, string palette)
{
string path = Environment.GetFolderPath (Environment.SpecialFolder.Personal);
string filePath = Path.Combine(path, "ARCSDev");
Loader loader = new Loader (filePath);
Run Code Online (Sandbox Code Playgroud)
但是我的应用程序似乎无法找到该文件,任何人都可以解释我做错了什么?
我正在尝试创建一个NSURL,其中包含项目内部音频文件的链接.我已经复制了音频文件(.m4a文件),我正在使用这一行用其中一个填充NSURL:
NSURL *fileToBePlayed = [[NSURL alloc] initWithString:[NSString stringWithString:[[NSBundle mainBundle] pathForResource:@"A3" ofType:@"m4a" inDirectory:@"Sounds"]]];
Run Code Online (Sandbox Code Playgroud)
我在这一行上遇到了以下崩溃:
2012-06-20 12:32:05.307 TestPlayer[29184:10703] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[NSPlaceholderString initWithString:]: nil argument'
Run Code Online (Sandbox Code Playgroud)
我不确定这nil argument是真的.肯定存在的文件,在正确的位置,已被复制到项目中,等等.我看不出有什么理由不能找到该文件.如果我将文件名更改为某个不在那里的虚构文件,我会得到同样的崩溃,因此可能由于某种原因它无法看到该文件.有任何想法吗?
如果我把它分成不同的行,这里前两行很好,它是崩溃的第三行,NSURL行:
NSString *testString = [[NSString alloc] init];
testString = [[NSBundle mainBundle] pathForResource:@"A3" ofType:@"m4a"];
NSURL *fileToBePlayed = [[NSURL alloc] initWithString:testString];
Run Code Online (Sandbox Code Playgroud) 我需要在我的应用程序的第一次运行时从主包中复制一些png到文档文件夹.我需要它,因为我必须将这些图像的文件路径保存在核心数据实体中.
我试过这种方式,但它不起作用,有谁知道为什么?
// to copy image from main bundle to documents folder
NSString* mainBundleFilePath = [[NSBundle mainBundle] pathForResource:@"SbriciolataDiRicotta" ofType:@"png"];
NSArray *destPath = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [destPath objectAtIndex:0];
NSData *mainBundleFile = [NSData dataWithContentsOfFile:mainBundleFilePath];
[[NSFileManager defaultManager] createFileAtPath:documentsDirectory
contents:mainBundleFile
attributes:nil];
// to save the file path
NSString*nomeImmagine = [[NSString alloc] initWithFormat:@"SbriciolataDiRicotta"];
NSString *pngFilePath = [NSString stringWithFormat:@"%@/%@.png",documentsDirectory, nomeImmagine];
Run Code Online (Sandbox Code Playgroud)
谢谢
mainbundle ×6
ios ×4
c# ×1
filepath ×1
iphone ×1
mp4 ×1
nsurl ×1
objective-c ×1
swift3 ×1
video ×1
xamarin.ios ×1
xcode ×1