0

I have been trying to stream videos using the open source Exo player but I am having a null pointer exception. I have taken the sample code from the Exo player developers guide. Please don't suggest to use Exo Media. I would like to implement it using Exo player only. Hoping somebody can guide/point me in the right direction at the very least. surfaceView = (SurfaceView) findViewById(R.id.videoView); LoadControl loadControl= new DefaultLoadControl(new DefaultAllocator(BUFFER_SEGMENT_SIZE)); DefaultBandwidthMeter bandwidthMeter=new DefaultBandwidthMeter(); MediaPresentationDescriptionParser parser=new MediaPresentationDescriptionParser(); UriDataSource manifestDataSource=new DefaultUriDataSource(MainActivity.this,USER_AGENT); ManifestFetcher<MediaPresentationDescription> manifestFetcher=new ManifestFetcher<>(TEST_URL,manifestDataSource,parser);

    //Video renderer
    DataSource dataSource=new DefaultUriDataSource(MainActivity.this,bandwidthMeter,USER_AGENT);
    ChunkSource videoChunkSource=new DashChunkSource(manifestFetcher,
            DefaultDashTrackSelector.newVideoInstance(MainActivity.this,true,false),
            dataSource,new AdaptiveEvaluator(bandwidthMeter),
            LIVE_EDGE_LATENCY_MS,elapsedRealtimeOffset,
            null,null,TYPE_VIDEO);   // ***** NPE in this line ***
    ChunkSampleSource videoSampleSource=new ChunkSampleSource(videoChunkSource,loadControl, VIDEO_BUFFER_SEGMENTS*BUFFER_SEGMENT_SIZE);
    MediaCodecVideoTrackRenderer videoTrackRenderer=new MediaCodecVideoTrackRenderer(MainActivity.this,videoSampleSource,MediaCodecSelector.DEFAULT,MediaCodec.VIDEO_SCALING_MODE_SCALE_TO_FIT);


    //Audio renderer
    DataSource audioDataSource=new DefaultUriDataSource(MainActivity.this,bandwidthMeter,USER_AGENT);
    ChunkSource audioChunkSource=new DashChunkSource(manifestFetcher,DefaultDashTrackSelector.newAudioInstance(),audioDataSource,null,LIVE_EDGE_LATENCY_MS,elapsedRealtimeOffset,null,null,TYPE_AUDIO);
    ChunkSampleSource audioSampleSource=new ChunkSampleSource(audioChunkSource,loadControl,AUDIO_BUFFER_SEGMENTS*BUFFER_SEGMENT_SIZE);
    MediaCodecAudioTrackRenderer audioTrackRenderer=new MediaCodecAudioTrackRenderer(audioSampleSource,MediaCodecSelector.DEFAULT);

LOG

03-01 17:10:53.792 32222-32222/com.example.tinfimate.exotest1 E/AndroidRuntime: FATAL EXCEPTION: main
                                                                            java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.tinfimate.exotest1/com.example.tinfimate.exotest1.MainActivity}: java.lang.NullPointerException
                                                                                at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2306)
                                                                                at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2358)
                                                                                at android.app.ActivityThread.access$600(ActivityThread.java:156)
                                                                                at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1340)
                                                                                at android.os.Handler.dispatchMessage(Handler.java:99)
                                                                                at android.os.Looper.loop(Looper.java:153)
                                                                                at android.app.ActivityThread.main(ActivityThread.java:5299)
                                                                                at java.lang.reflect.Method.invokeNative(Native Method)
                                                                                at java.lang.reflect.Method.invoke(Method.java:511)
                                                                                at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:833)
                                                                                at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
                                                                                at dalvik.system.NativeStart.main(Native Method)
                                                                             Caused by: java.lang.NullPointerException
                                                                                at com.google.android.exoplayer.dash.DashChunkSource.<init>(DashChunkSource.java:276)
                                                                                at com.google.android.exoplayer.dash.DashChunkSource.<init>(DashChunkSource.java:215)
                                                                                at com.example.tinfimate.exotest1.MainActivity.onCreate(MainActivity.java:87)
                                                                                at android.app.Activity.performCreate(Activity.java:5122)
                                                                                at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1081)
                                                                                at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2270)
                                                                                at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2358) 
                                                                                at android.app.ActivityThread.access$600(ActivityThread.java:156) 
                                                                                at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1340) 
                                                                                at android.os.Handler.dispatchMessage(Handler.java:99) 
                                                                                at android.os.Looper.loop(Looper.java:153) 
                                                                                at android.app.ActivityThread.main(ActivityThread.java:5299) 
                                                                                at java.lang.reflect.Method.invokeNative(Native Method) 
                                                                                at java.lang.reflect.Method.invoke(Method.java:511) 
                                                                                at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:833) 
                                                                                at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600) 
                                                                                at dalvik.system.NativeStart.main(Native Method) 
Infimate
  • 43
  • 1
  • 7
  • Please add your stack trace – jonathanrz Mar 01 '16 at 11:51
  • i have added the stack trace – Infimate Mar 01 '16 at 12:01
  • Please add your MainActivity onCreate source – jonathanrz Mar 01 '16 at 12:03
  • The above code is from the MainActivity onCreate block – Infimate Mar 01 '16 at 12:12
  • Can you tell me what is line 87? – jonathanrz Mar 01 '16 at 12:14
  • ChunkSource videoChunkSource=new DashChunkSource ... //this is line 87 .I have added the NPE error at the end of the line – Infimate Mar 01 '16 at 12:15
  • Possible duplicate of [What is a Null Pointer Exception, and how do I fix it?](http://stackoverflow.com/questions/218384/what-is-a-null-pointer-exception-and-how-do-i-fix-it) –  Mar 01 '16 at 12:18
  • @RC. it is not a duplicate – jonathanrz Mar 01 '16 at 12:51
  • @Infimate please check if any of the objects that you are passing as a parameter isn't null – jonathanrz Mar 01 '16 at 12:51
  • @jonathanrz Yes, i have checked each parameters and no null objects.Tracing back the logs i am suspicious about the 1st parameter(manifestFetcher) .Looking at the DashChunkSource class , particularly at the constructor 1st parameter(manifestFetcher) the docs says this ->manifestFetcher:A fetcher for the manifest, which must have already successfully completed an initial load. Is there any chance the NPE error could mean that the manifestFetcher is not loaded? – Infimate Mar 01 '16 at 13:04
  • Have you debugged it and checked which of the parameters are/is null? – Joakim Sandqvist Mar 01 '16 at 13:24
  • https://github.com/google/ExoPlayer/blob/master/library/src/main/java/com/google/android/exoplayer/dash/DashChunkSource.java#L276 initialManifest is null (if the source is the correct one) or `.dynamic` is a null Boolean –  Mar 01 '16 at 13:45
  • @JoakimSandqvist : yes i debugged it .I added a few breakpoints to check the values of the objects and i have found that when it comes to instantiating the AdaptiveEvaluator, the debug info automatically clears itself and the debug would stop after this.Does this mean that the AdaptiveEvaluator is at fault here ? – Infimate Mar 01 '16 at 13:45
  • @RC. : yes this is the source code.I checked the declaration of the variable boolean dynamic of MediaPresentationDescription class and it has not been initialized.And the variable has been declared final !! `public class MediaPresentationDescription implements RedirectingManifest { public final long availabilityStartTime; public final long duration; public final long minBufferTime; public final boolean dynamic;` – Infimate Mar 01 '16 at 13:57
  • I'm no expert in this library but looking at [this sample](https://github.com/google/ExoPlayer/blob/master/demo/src/main/java/com/google/android/exoplayer/demo/player/DashRendererBuilder.java), the mediaFetcher is used in some async call. So I think you need some call to [`singleLoad()`](https://google.github.io/ExoPlayer/doc/reference/com/google/android/exoplayer/util/ManifestFetcher.html#singleLoad(android.os.Looper,%20com.google.android.exoplayer.util.ManifestFetcher.ManifestCallback)) with an appropriate callback –  Mar 01 '16 at 14:35
  • i executed the singleLoad method , implemented the manifestfetcher callback still getting the same error – Infimate Mar 02 '16 at 06:13

0 Answers0