3

私はハイブリッド Web アプリとネイティブ iOS アプリを構築しており、ローカル デバイスに記録され、NSDocumentDirectory に保存されているビデオを表示して、UIWebView に表示しようとしています。

現在、これは以下のコードに基づいて機能していないようです。ファイルは存在しますが、HTML からのファイルへの参照が正しくない可能性があります。

NSArray   *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES);
NSString  *documentsDirectory = [paths objectAtIndex:0];
NSString  *videoPath = [documentsDirectory stringByAppendingPathComponent:[NSString stringWithFormat:@"%@.mp4",fileName]];

BOOL fileExist =  [[NSFileManager defaultManager] fileExistsAtPath:videoPath];    
if(fileExist) {
    NSLog(@"File Exist in path");
} else {
    NSLog(@"NO File Exist");
}

videoPath = [videoPath stringByReplacingOccurrencesOfString:@"/" withString:@"//"];
videoPath = [videoPath stringByReplacingOccurrencesOfString:@" " withString:@"%20"];

NSString *htmlString = [NSString stringWithFormat:@"<video width=\"320\" height=\"240\" controls><source src=\"%@\" type=\"video/mp4\"></video>", [NSString stringWithFormat:@"file://%@/",videoPath]];
NSString *js = [NSString stringWithFormat:@"document.getElementById('videoList').innerHTML = '%@'", htmlString];
NSString *result = [self.livingWebView stringByEvaluatingJavaScriptFromString:js];

NSLog(@"Result: %@", result);

The output of the JavaScript injection is:

Result: <video width="320" height="240" controls><source src="file:////var//mobile//Applications//76FE06FB-39D3-4658-8B52-AFE9DBE0C524//Documents//23-07-2013-16-54-48.mp4/" type="video/mp4"></video>

どんな助けでも感謝します。

4

1 に答える 1

0

NSURL *url = [NSURL fileURLWithPath:videoPath];を使用して、パスを file:// URL に変換する必要があります。次に、それを htmlString に入れます。stringByReplaceingOccurencesOfString で行っている手動の操作を行わないでください。いくつかの変換が欠落しています。

于 2013-07-23T16:42:27.003 に答える