Reject any native video player calls on iOS that point to files within .pck archives.
Fix the paths for both res:// and user:// specified video files.
This commit is contained in:
parent
6a25a647b7
commit
7b25641813
|
@ -689,6 +689,10 @@ void _OS::native_video_pause() {
|
|||
OS::get_singleton()->native_video_pause();
|
||||
};
|
||||
|
||||
void _OS::native_video_unpause() {
|
||||
OS::get_singleton()->native_video_unpause();
|
||||
};
|
||||
|
||||
void _OS::native_video_stop() {
|
||||
|
||||
OS::get_singleton()->native_video_stop();
|
||||
|
@ -874,6 +878,7 @@ void _OS::_bind_methods() {
|
|||
ObjectTypeDB::bind_method(_MD("native_video_is_playing"),&_OS::native_video_is_playing);
|
||||
ObjectTypeDB::bind_method(_MD("native_video_stop"),&_OS::native_video_stop);
|
||||
ObjectTypeDB::bind_method(_MD("native_video_pause"),&_OS::native_video_pause);
|
||||
ObjectTypeDB::bind_method(_MD("native_video_unpause"),&_OS::native_video_unpause);
|
||||
|
||||
ObjectTypeDB::bind_method(_MD("get_scancode_string","code"),&_OS::get_scancode_string);
|
||||
ObjectTypeDB::bind_method(_MD("is_scancode_unicode","code"),&_OS::is_scancode_unicode);
|
||||
|
|
|
@ -131,6 +131,7 @@ public:
|
|||
Error native_video_play(String p_path, float p_volume, String p_audio_track, String p_subtitle_track);
|
||||
bool native_video_is_playing();
|
||||
void native_video_pause();
|
||||
void native_video_unpause();
|
||||
void native_video_stop();
|
||||
|
||||
void set_iterations_per_second(int p_ips);
|
||||
|
|
|
@ -478,6 +478,10 @@ void OS::native_video_pause() {
|
|||
|
||||
};
|
||||
|
||||
void OS::native_video_unpause() {
|
||||
|
||||
};
|
||||
|
||||
void OS::native_video_stop() {
|
||||
|
||||
};
|
||||
|
|
|
@ -376,6 +376,7 @@ public:
|
|||
virtual Error native_video_play(String p_path, float p_volume, String p_audio_track, String p_subtitle_track);
|
||||
virtual bool native_video_is_playing() const;
|
||||
virtual void native_video_pause();
|
||||
virtual void native_video_unpause();
|
||||
virtual void native_video_stop();
|
||||
|
||||
virtual bool can_use_threads() const;
|
||||
|
|
|
@ -58,6 +58,7 @@ void _show_keyboard(String);
|
|||
void _hide_keyboard();
|
||||
bool _play_video(String, float, String, String);
|
||||
bool _is_video_playing();
|
||||
void _pause_video();
|
||||
void _focus_out_video();
|
||||
void _unpause_video();
|
||||
void _stop_video();
|
||||
|
@ -74,64 +75,30 @@ void _hide_keyboard() {
|
|||
keyboard_text = "";
|
||||
};
|
||||
|
||||
/*
|
||||
bool _play_video(String p_path, float p_volume) {
|
||||
|
||||
float player_volume = p_volume * AudioServer::get_singleton()->get_singleton()->get_stream_global_volume_scale();
|
||||
video_previous_volume = [[MPMusicPlayerController applicationMusicPlayer] volume];
|
||||
|
||||
//[[MPMusicPlayerController applicationMusicPlayer] setVolume: player_volume];
|
||||
|
||||
p_path = Globals::get_singleton()->globalize_path(p_path);
|
||||
|
||||
NSString* file_path = [[[NSString alloc] initWithUTF8String:p_path.utf8().get_data()] autorelease];
|
||||
NSURL *file_url = [NSURL fileURLWithPath:file_path];
|
||||
|
||||
_instance.moviePlayerController = [[MPMoviePlayerController alloc] initWithContentURL:file_url];
|
||||
_instance.moviePlayerController.controlStyle = MPMovieControlStyleNone;
|
||||
[_instance.moviePlayerController setScalingMode:MPMovieScalingModeAspectFit];
|
||||
//[_instance.moviePlayerController setScalingMode:MPMovieScalingModeAspectFill];
|
||||
|
||||
[[NSNotificationCenter defaultCenter] addObserver:_instance
|
||||
selector:@selector(moviePlayBackDidFinish:)
|
||||
name:MPMoviePlayerPlaybackDidFinishNotification
|
||||
object:_instance.moviePlayerController];
|
||||
|
||||
[_instance.moviePlayerController.view setFrame:_instance.bounds];
|
||||
_instance.moviePlayerController.view.userInteractionEnabled = NO;
|
||||
[_instance addSubview:_instance.moviePlayerController.view];
|
||||
[_instance.moviePlayerController play];
|
||||
|
||||
video_playing = true;
|
||||
|
||||
return true;
|
||||
}
|
||||
*/
|
||||
|
||||
bool _play_video(String p_path, float p_volume, String p_audio_track, String p_subtitle_track) {
|
||||
p_path = Globals::get_singleton()->globalize_path(p_path);
|
||||
|
||||
NSString* file_path = [[[NSString alloc] initWithUTF8String:p_path.utf8().get_data()] autorelease];
|
||||
//NSURL *file_url = [NSURL fileURLWithPath:file_path];
|
||||
|
||||
_instance.avAsset = [AVAsset assetWithURL:[NSURL fileURLWithPath:file_path]];
|
||||
|
||||
_instance.avPlayerItem =[[AVPlayerItem alloc]initWithAsset:_instance.avAsset];
|
||||
[_instance.avPlayerItem addObserver:_instance forKeyPath:@"status" options:0 context:nil];
|
||||
|
||||
_instance.avPlayer = [[AVPlayer alloc]initWithPlayerItem:_instance.avPlayerItem];
|
||||
_instance.avPlayerLayer =[AVPlayerLayer playerLayerWithPlayer:_instance.avPlayer];
|
||||
_instance.avPlayer = [[AVPlayer alloc]initWithPlayerItem:_instance.avPlayerItem];
|
||||
_instance.avPlayerLayer =[AVPlayerLayer playerLayerWithPlayer:_instance.avPlayer];
|
||||
|
||||
[_instance.avPlayer addObserver:_instance forKeyPath:@"status" options:0 context:nil];
|
||||
[[NSNotificationCenter defaultCenter] addObserver:_instance
|
||||
[_instance.avPlayer addObserver:_instance forKeyPath:@"status" options:0 context:nil];
|
||||
[[NSNotificationCenter defaultCenter] addObserver:_instance
|
||||
selector:@selector(playerItemDidReachEnd:)
|
||||
name:AVPlayerItemDidPlayToEndTimeNotification
|
||||
object:[_instance.avPlayer currentItem]];
|
||||
|
||||
[_instance.avPlayer addObserver:_instance forKeyPath:@"rate" options:NSKeyValueObservingOptionNew context:0];
|
||||
|
||||
[_instance.avPlayerLayer setFrame:_instance.bounds];
|
||||
[_instance.layer addSublayer:_instance.avPlayerLayer];
|
||||
[_instance.avPlayer play];
|
||||
[_instance.avPlayerLayer setFrame:_instance.bounds];
|
||||
[_instance.layer addSublayer:_instance.avPlayerLayer];
|
||||
[_instance.avPlayer play];
|
||||
|
||||
AVMediaSelectionGroup *audioGroup = [_instance.avAsset mediaSelectionGroupForMediaCharacteristic: AVMediaCharacteristicAudible];
|
||||
|
||||
|
@ -173,23 +140,19 @@ bool _play_video(String p_path, float p_volume, String p_audio_track, String p_s
|
|||
}
|
||||
}
|
||||
|
||||
video_playing = true;
|
||||
video_playing = true;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool _is_video_playing() {
|
||||
//NSInteger playback_state = _instance.moviePlayerController.playbackState;
|
||||
//return video_playing || _instance.moviePlayerController.playbackState == MPMoviePlaybackStatePlaying;
|
||||
//if (video_found_error)
|
||||
// return false;
|
||||
//return (_instance.moviePlayerController.playbackState == MPMoviePlaybackStatePlaying);
|
||||
|
||||
return video_playing || (_instance.avPlayer.rate > 0 && !_instance.avPlayer.error);
|
||||
if (_instance.avPlayer.error) {
|
||||
printf("Error during playback\n");
|
||||
}
|
||||
return (_instance.avPlayer.rate > 0 && !_instance.avPlayer.error);
|
||||
}
|
||||
|
||||
void _pause_video() {
|
||||
//[_instance.moviePlayerController pause];
|
||||
video_current_time = _instance.avPlayer.currentTime;
|
||||
[_instance.avPlayer pause];
|
||||
video_playing = false;
|
||||
|
@ -204,15 +167,9 @@ void _unpause_video() {
|
|||
|
||||
[_instance.avPlayer play];
|
||||
video_playing = true;
|
||||
|
||||
//video_current_time = kCMTimeZero;
|
||||
};
|
||||
|
||||
void _stop_video() {
|
||||
//[_instance.moviePlayerController stop];
|
||||
//[_instance.moviePlayerController.view removeFromSuperview];
|
||||
//[[MPMusicPlayerController applicationMusicPlayer] setVolume: video_previous_volume];
|
||||
|
||||
[_instance.avPlayer pause];
|
||||
[_instance.avPlayerLayer removeFromSuperlayer];
|
||||
_instance.avPlayer = nil;
|
||||
|
|
|
@ -41,6 +41,7 @@
|
|||
|
||||
#include "core/os/dir_access.h"
|
||||
#include "core/os/file_access.h"
|
||||
#include "core/io/file_access_pack.h"
|
||||
#include "core/globals.h"
|
||||
|
||||
#include "sem_iphone.h"
|
||||
|
@ -517,12 +518,25 @@ extern void _focus_out_video();
|
|||
Error OSIPhone::native_video_play(String p_path, float p_volume, String p_audio_track, String p_subtitle_track) {
|
||||
FileAccess* f = FileAccess::open(p_path, FileAccess::READ);
|
||||
bool exists = f && f->is_open();
|
||||
printf("file exists for %ls, %i, %p\n", p_path.c_str(), (int)exists, f);
|
||||
if (f)
|
||||
memdelete(f);
|
||||
|
||||
String tempFile = get_data_dir();
|
||||
if (!exists)
|
||||
return FAILED;
|
||||
if ( _play_video(p_path, p_volume, p_audio_track, p_subtitle_track) )
|
||||
|
||||
if (p_path.begins_with("res://")) {
|
||||
if (PackedData::get_singleton()->has_path(p_path)) {
|
||||
print("Unable to play %S using the native player as it resides in a .pck file\n", p_path.c_str());
|
||||
return ERR_INVALID_PARAMETER;
|
||||
} else {
|
||||
p_path = p_path.replace("res:/", Globals::get_singleton()->get_resource_path());
|
||||
}
|
||||
} else if (p_path.begins_with("user://"))
|
||||
p_path = p_path.replace("user:/", get_data_dir());
|
||||
|
||||
memdelete(f);
|
||||
|
||||
print("Playing video: %S\n", p_path.c_str());
|
||||
if (_play_video(p_path, p_volume, p_audio_track, p_subtitle_track) )
|
||||
return OK;
|
||||
return FAILED;
|
||||
}
|
||||
|
|
|
@ -195,12 +195,12 @@ public:
|
|||
void set_unique_ID(String p_ID);
|
||||
String get_unique_ID() const;
|
||||
|
||||
virtual Error native_video_play(String p_path, float p_volume, String p_audio_track, String p_subtitle_track);
|
||||
virtual bool native_video_is_playing() const;
|
||||
virtual void native_video_pause();
|
||||
virtual Error native_video_play(String p_path, float p_volume, String p_audio_track, String p_subtitle_track);
|
||||
virtual bool native_video_is_playing() const;
|
||||
virtual void native_video_pause();
|
||||
virtual void native_video_unpause();
|
||||
virtual void native_video_focus_out();
|
||||
virtual void native_video_stop();
|
||||
virtual void native_video_stop();
|
||||
|
||||
OSIPhone(int width, int height);
|
||||
~OSIPhone();
|
||||
|
|
Loading…
Reference in New Issue