あなたは、あなたが置いたファイルでMPMoviePlayerControllerを動作させることができますか?
もしそうなら、これを試してみてください。
string newVideoPath = Path.GetFileName(videopath);
mp = new MPMoviePlayerController(NSUrl.FromFilename(newVideoPath));
EDIT(もっと精巧な答え):
変更するには、この本から行:これに
var videopath = Path.Combine (doc, filename);
:
string videopath = Path.Combine (doc, filename);
そして、このような何かを実装。
public void PlayVideo(string videopath)
{
string name = Path.GetFileName(videopath);
Device.BeginInvokeOnMainThread(() =>
{
QLPreviewItemFileSystem prevItem = new QLPreviewItemFileSystem(name, videopath);
QLPreviewController previewController = new QLPreviewController();
previewController.DataSource = new PreviewControllerDS(prevItem);
UIApplication.SharedApplication.KeyWindow.RootViewController.PresentViewController(previewController, true, null);
});
}
public class PreviewControllerDS : QLPreviewControllerDataSource
{
private QLPreviewItem _item;
public PreviewControllerDS(QLPreviewItem item)
{
_item = item;
}
public override IQLPreviewItem GetPreviewItem(QLPreviewController controller, nint index)
{
return _item;
}
public override nint PreviewItemCount(QLPreviewController controller)
{
return 1;
}
}
public class QLPreviewItemFileSystem : QLPreviewItem
{
string _fileName, _filePath;
public QLPreviewItemFileSystem(string fileName, string filePath)
{
_fileName = fileName;
_filePath = filePath;
}
public override string ItemTitle
{
get
{
return _fileName;
}
}
public override NSUrl ItemUrl
{
get
{
return NSUrl.FromFilename(_filePath);
}
}
}
そして、あなたが呼び出す必要がある時はいつでも、それはこれを使用するには:
PlayVideo(videopath);
これはまた、あなたが将来的ににあなたが選択する必要があり、他のファイルを開くことができます。 (pdfs、画像など)注:まだテストしていないので、コードを修正する必要があるかもしれません。
編集:MPMoviePlayerControllerはiOS9以降では廃止されているため、実際にはAVPlayerを使用する必要があります。例のドキュメントを読む: https://developer.xamarin.com/recipes/ios/media/video_and_photos/play_a_video_using_avplayer/ – Gerrit
ちょうど質問がありました。あなたはあなたが探しているビデオの名前を入れているのですか?全体のビデオパス、私はどちらかのために働くことができません。私は準備が整ったビデオを手に入れようとしています。 – oisin1min
https://developer.xamarin.com/samples/monotouch/MoviePlayback/ これは私がビデオを再生する方法です。ビデオを再生するこの悪い方法は、おそらく問題です – oisin1min