FlutterIJK.m 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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. @end
  10. @interface FlutterIJK ()
  11. @end
  12. @implementation FlutterIJK {
  13. int64_t textureId;
  14. IJKVideoPlayer *player;
  15. }
  16. - (instancetype)initWithRegistrar:(NSObject <FlutterPluginRegistrar> *)registrar {
  17. self = [super init];
  18. if (self) {
  19. self.registrar = registrar;
  20. IJKMPMoviePlayerController *controller = [[IJKMPMoviePlayerController alloc] initWithContentURLString:@""];
  21. NSObject <FlutterTextureRegistry> *textures = [self.registrar textures];
  22. textureId = [textures registerTexture:player];
  23. }
  24. return self;
  25. }
  26. + (instancetype)ijkWithRegistrar:(NSObject <FlutterPluginRegistrar> *)registrar {
  27. return [[self alloc] initWithRegistrar:registrar];
  28. }
  29. - (int64_t)id {
  30. return textureId;
  31. }
  32. @end
  33. @implementation IJKVideoPlayer {
  34. IJKFFMoviePlayerController *controller;
  35. }
  36. - (instancetype)init {
  37. self = [super init];
  38. if (self) {
  39. IJKFFOptions *options = [IJKFFOptions optionsByDefault];
  40. NSString *urlString = @"https://www.sample-videos.com/video123/mp4/720/big_buck_bunny_720p_1mb.mp4";
  41. controller = [[IJKFFMoviePlayerController alloc] initWithContentURLString:urlString withOptions:options];
  42. [controller prepareToPlay];
  43. [controller play];
  44. }
  45. return self;
  46. }
  47. - (CVPixelBufferRef _Nullable)copyPixelBuffer {
  48. return [controller framePixelbuffer];
  49. }
  50. @end