skip to Main Content

I’m using video player controller to play video .I’m getting video URL from API and then I’m initializing that using video player controller . When I upload video from my app after uploading i’m getting url that is playing in my app .but when i’m using video url that is uploaded from admin(angular) its not playing in my app.
error

E/ExoPlayerImplInternal(13211): Playback error
E/ExoPlayerImplInternal(13211):   com.google.android.exoplayer2.ExoPlaybackException: Source error
E/ExoPlayerImplInternal(13211):       at com.google.android.exoplayer2.ExoPlayerImplInternal.handleIoException(ExoPlayerImplInternal.java:644)
E/ExoPlayerImplInternal(13211):       at com.google.android.exoplayer2.ExoPlayerImplInternal.handleMessage(ExoPlayerImplInternal.java:614)
E/ExoPlayerImplInternal(13211):       at android.os.Handler.dispatchMessage(Handler.java:102)
E/ExoPlayerImplInternal(13211):       at android.os.Looper.loop(Looper.java:257)
E/ExoPlayerImplInternal(13211):       at android.os.HandlerThread.run(HandlerThread.java:67)
E/ExoPlayerImplInternal(13211):   Caused by: com.google.android.exoplayer2.ParserException: Missing CodecPrivate for codec V_MPEG4/ISO/AVC
E/ExoPlayerImplInternal(13211):       at com.google.android.exoplayer2.extractor.mkv.MatroskaExtractor$Track.getCodecPrivate(MatroskaExtractor.java:2548)
E/ExoPlayerImplInternal(13211):       at com.google.android.exoplayer2.extractor.mkv.MatroskaExtractor$Track.initializeOutput(MatroskaExtractor.java:2074)
E/ExoPlayerImplInternal(13211):       at com.google.android.exoplayer2.extractor.mkv.MatroskaExtractor.endMasterElement(MatroskaExtractor.java:812)
E/ExoPlayerImplInternal(13211):       at com.google.android.exoplayer2.extractor.mkv.MatroskaExtractor$InnerEbmlProcessor.endMasterElement(MatroskaExtractor.java:1947)
E/ExoPlayerImplInternal(13211):       at com.google.android.exoplayer2.extractor.mkv.DefaultEbmlReader.read(DefaultEbmlReader.java:88)
E/ExoPlayerImplInternal(13211):       at com.google.android.exoplayer2.extractor.mkv.MatroskaExtractor.read(MatroskaExtractor.java:512)
E/ExoPlayerImplInternal(13211):       at com.google.android.exoplayer2.source.BundledExtractorsAdapter.read(BundledExtractorsAdapter.java:127)
E/ExoPlayerImplInternal(13211):       at com.google.android.exoplayer2.source.ProgressiveMediaPeriod$ExtractingLoadable.load(ProgressiveMediaPeriod.java:1039)
E/ExoPlayerImplInternal(13211):       at com.google.android.exoplayer2.upstream.Loader$LoadTask.run(Loader.java:412)
E/ExoPlayerImplInternal(13211):       at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
E/ExoPlayerImplInternal(13211):       at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
E/ExoPlayerImplInternal(13211):       at java.lang.Thread.run(Thread.java:923)
I/flutter (13211): Error initializing video player: PlatformException(VideoError, Video player had error com.google.android.exoplayer2.ExoPlaybackException: Source error, null, null)

`your text`my code
void initializeVideoPlayer(String url) {
    kycController.videoPlayerController = VideoPlayerController.networkUrl(
      Uri.parse(url),
      videoPlayerOptions: VideoPlayerOptions(mixWithOthers: false,allowBackgroundPlayback:false),

    )
      ..initialize().then(
        (_) async {
          if (mounted) {
            setState(() {
              kycController.videoPlayerController!.play();
            });
            kycController.videoPlayerController!.addListener(
              () {
                if (kycController.videoPlayerController!.value.position == kycController.videoPlayerController!.value.duration) {
                  setState(() {
                    kycController.videoPlayerController!.pause();
                    kycController.videoPlayerController!.seekTo(const Duration(seconds: 0));
                  });
                }
              },
            );
          }
        },
        onError: (error) {
          // Handle initialization error
          debugPrint("Error initializing video player: $error");
        },
      );
  }

2

Answers


  1. your code look good

    try this

    void initializeVideoPlayer(String url) {
    kycController.videoPlayerController = VideoPlayerController.networkUrl(
      url, // here change 
      videoPlayerOptions: VideoPlayerOptions(mixWithOthers: false,allowBackgroundPlayback:false),
    
    )
      ..initialize().then(
        (_) async {
          if (mounted) {
            setState(() {
              kycController.videoPlayerController!.play();
            });
            kycController.videoPlayerController!.addListener(
              () {
                if (kycController.videoPlayerController!.value.position == kycController.videoPlayerController!.value.duration) {
                  setState(() {
                    kycController.videoPlayerController!.pause();
                    kycController.videoPlayerController!.seekTo(const Duration(seconds: 0));
                  });
                }
              },
            );
          }
        },
        onError: (error) {
          // Handle initialization error
          debugPrint("Error initializing video player: $error");
        },
      );
    

    }

    change Uri.parse(url) to pass only url

    Login or Signup to reply.
  2. You can use the internet so check internet Permission

    <uses-permission android:name="android.permission.INTERNET"/>
    

    Use this plugin :
    video_player 2.8.2

    import 'package:flutter/material.dart';
    import 'package:video_player/video_player.dart';
    
    class VideoPlayerDemo extends StatefulWidget {
      @override
      _VideoPlayerDemoState createState() => _VideoPlayerDemoState();
    }
    
    class _VideoPlayerDemoState extends State<VideoPlayerDemo> {
      late VideoPlayerController _videoPlayerController;
    
      @override
      void initState() {
        super.initState();
        initializeVideoPlayer("ENTER_YOUR_VIDEO_URL");
      }
    
      void initializeVideoPlayer(String url) {
        _videoPlayerController = VideoPlayerController.network(
          url,
          videoPlayerOptions: VideoPlayerOptions(mixWithOthers: false, allowBackgroundPlayback: false),
        );
    
        _videoPlayerController.initialize().then(
          (_) async {
            if (mounted) {
              setState(() {
                _videoPlayerController.play();
              });
    
              _videoPlayerController.addListener(() {
                if (_videoPlayerController.value.position == _videoPlayerController.value.duration) {
                  setState(() {
                    _videoPlayerController.pause();
                    _videoPlayerController.seekTo(const Duration(seconds: 0));
                  });
                }
              });
            }
          },
          onError: (error) {
            debugPrint("Error initializing video player: $error");
          },
        );
      }
    
      @override
      void dispose() {
        _videoPlayerController.dispose();
        super.dispose();
      }
    
      @override
      Widget build(BuildContext context) {
        return Scaffold(
          appBar: AppBar(
            title: Text('Video Player Demo'),
          ),
          body: Center(
            child: AspectRatio(
              aspectRatio: _videoPlayerController.value.aspectRatio,
              child: VideoPlayer(_videoPlayerController),
            ),
          ),
        );
      }
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search