FlutterIJK.m 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. //
  2. // Created by Caijinglong on 2019-03-08.
  3. //
  4. #import "FlutterIJK.h"
  5. #import <IJKMediaFramework/IJKMediaFramework.h>
  6. #import <IJKMediaFramework/IJKMediaPlayer.h>
  7. #import <AVFoundation/AVFoundation.h>
  8. @interface IJKVideoPlayer : NSObject <FlutterTexture>
  9. @property(nonatomic, strong) IJKFFMoviePlayerController *controller;
  10. - (void)setDataSource:(NSString *)uri;
  11. @end
  12. @interface FlutterIJK ()
  13. @end
  14. @implementation FlutterIJK {
  15. int64_t textureId;
  16. IJKVideoPlayer *player;
  17. }
  18. - (instancetype)initWithRegistrar:(NSObject <FlutterPluginRegistrar> *)registrar {
  19. self = [super init];
  20. if (self) {
  21. self.registrar = registrar;
  22. NSObject <FlutterTextureRegistry> *textures = [self.registrar textures];
  23. player = [IJKVideoPlayer new];
  24. textureId = [textures registerTexture:player];
  25. }
  26. return self;
  27. }
  28. + (instancetype)ijkWithRegistrar:(NSObject <FlutterPluginRegistrar> *)registrar {
  29. return [[self alloc] initWithRegistrar:registrar];
  30. }
  31. - (int64_t)id {
  32. return textureId;
  33. }
  34. - (void)dispose {
  35. IJKFFMoviePlayerController *ctl = [player controller];
  36. [ctl stop];
  37. [ctl shutdown];
  38. }
  39. - (void)play {
  40. IJKFFMoviePlayerController *ctl = [player controller];
  41. [ctl play];
  42. }
  43. - (void)pause {
  44. [[player controller] pause];
  45. }
  46. - (void)stop {
  47. [[player controller] stop];
  48. }
  49. - (void)setDateSourceWithUri:(NSString *)uri {
  50. [player setDataSource:uri];
  51. }
  52. @end
  53. @implementation IJKVideoPlayer {
  54. // IJKFFMoviePlayerController *controller;
  55. }
  56. - (instancetype)init {
  57. self = [super init];
  58. if (self) {
  59. }
  60. return self;
  61. }
  62. - (CVPixelBufferRef _Nullable)copyPixelBuffer {
  63. [self.controller framePixelbufferLock];
  64. CVPixelBufferRef pixelBuffer = [self.controller framePixelbuffer];
  65. [self.controller framePixelbufferUnlock];
  66. NSLog(@"buffer = %@",pixelBuffer);
  67. return pixelBuffer;
  68. }
  69. - (void)setDataSource:(NSString *)uri {
  70. IJKFFOptions *options = [IJKFFOptions optionsByDefault];
  71. self.controller = [[IJKFFMoviePlayerController alloc] initWithContentURLString:uri withOptions:options];
  72. [self.controller prepareToPlay];
  73. }
  74. @end