diff options
author | punto- <ariel@godotengine.org> | 2016-02-19 02:32:41 -0300 |
---|---|---|
committer | punto- <ariel@godotengine.org> | 2016-02-19 02:32:41 -0300 |
commit | 336f69b2144e978dcc98e2a0b4dd00022e46a43b (patch) | |
tree | 00f22a2608f7065dc4a0e338acbe4e21b17690cc | |
parent | 6a25a647b73e352f3c447cb97bdf01550be4a6cd (diff) | |
parent | 7b25641813b950e1e81a84e7b0392dcbddfb1011 (diff) |
Merge pull request #3770 from kurikaesu/Native-Video-Player-enhancements
Reject any native video player calls on iOS that point to files withi…
-rw-r--r-- | core/bind/core_bind.cpp | 5 | ||||
-rw-r--r-- | core/bind/core_bind.h | 1 | ||||
-rw-r--r-- | core/os/os.cpp | 4 | ||||
-rw-r--r-- | core/os/os.h | 1 | ||||
-rwxr-xr-x | platform/iphone/gl_view.mm | 71 | ||||
-rw-r--r-- | platform/iphone/os_iphone.cpp | 22 | ||||
-rw-r--r-- | platform/iphone/os_iphone.h | 8 |
7 files changed, 47 insertions, 65 deletions
diff --git a/core/bind/core_bind.cpp b/core/bind/core_bind.cpp index b291ee396b..229640ba11 100644 --- a/core/bind/core_bind.cpp +++ b/core/bind/core_bind.cpp @@ -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); diff --git a/core/bind/core_bind.h b/core/bind/core_bind.h index 30cc93fa11..4a9bb2a961 100644 --- a/core/bind/core_bind.h +++ b/core/bind/core_bind.h @@ -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); diff --git a/core/os/os.cpp b/core/os/os.cpp index 0bc06c8375..1aee6d9aa2 100644 --- a/core/os/os.cpp +++ b/core/os/os.cpp @@ -478,6 +478,10 @@ void OS::native_video_pause() { }; +void OS::native_video_unpause() { + +}; + void OS::native_video_stop() { }; diff --git a/core/os/os.h b/core/os/os.h index 0d4edb035d..a80b81bfa2 100644 --- a/core/os/os.h +++ b/core/os/os.h @@ -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; diff --git a/platform/iphone/gl_view.mm b/platform/iphone/gl_view.mm index 88361e87e4..94fbb9e174 100755 --- a/platform/iphone/gl_view.mm +++ b/platform/iphone/gl_view.mm @@ -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; diff --git a/platform/iphone/os_iphone.cpp b/platform/iphone/os_iphone.cpp index ec62cb5c26..9f6b8433aa 100644 --- a/platform/iphone/os_iphone.cpp +++ b/platform/iphone/os_iphone.cpp @@ -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; } diff --git a/platform/iphone/os_iphone.h b/platform/iphone/os_iphone.h index abe797fed1..d34e8bfe95 100644 --- a/platform/iphone/os_iphone.h +++ b/platform/iphone/os_iphone.h @@ -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(); |