0

I am using a TextureView to play a video from my App-Engine server. I can play the video fine if I open the link in a browser. But MediaPlay has the following errors about file not found and then not being about to play the video

I/MediaPlayer: Need to enable context aware info
 E/MediaPlayer-JNI: QCMediaPlayer mediaplayer NOT present
 D/MediaPlayer: setDataSource IOException happend : 
 D/MediaPlayer: java.io.FileNotFoundException: No content provider: https://companycloud.appspot.com/watchvideo/?videoid=1234567771234567
 D/MediaPlayer:     at android.content.ContentResolver.openTypedAssetFileDescriptor(ContentResolver.java:1074)
 D/MediaPlayer:     at android.content.ContentResolver.openAssetFileDescriptor(ContentResolver.java:927)
 D/MediaPlayer:     at android.content.ContentResolver.openAssetFileDescriptor(ContentResolver.java:854)
 D/MediaPlayer:     at android.media.MediaPlayer.setDataSource(MediaPlayer.java:1085)
 D/MediaPlayer:     at android.media.MediaPlayer.setDataSource(MediaPlayer.java:1059)
 D/MediaPlayer:     at com.company.app.android.fragment.VideoFragment.playNewVideo(VideoFragment.java:411)
 D/MediaPlayer:     at com.company.app.android.fragment.VideoFragment.access$400(VideoFragment.java:63)
 D/MediaPlayer:     at com.company.app.android.fragment.VideoFragment$1.onReceive(VideoFragment.java:120)
 D/MediaPlayer:     at android.support.v4.content.LocalBroadcastManager.executePendingBroadcasts(LocalBroadcastManager.java:297)
 D/MediaPlayer:     at android.support.v4.content.LocalBroadcastManager.access$000(LocalBroadcastManager.java:46)
 D/MediaPlayer:     at android.support.v4.content.LocalBroadcastManager$1.handleMessage(LocalBroadcastManager.java:116)
 D/MediaPlayer:     at android.os.Handler.dispatchMessage(Handler.java:102)
 D/MediaPlayer:     at android.os.Looper.loop(Looper.java:145)
 D/MediaPlayer:     at android.app.ActivityThread.main(ActivityThread.java:5837)
 D/MediaPlayer:     at java.lang.reflect.Method.invoke(Native Method)
 D/MediaPlayer:     at java.lang.reflect.Method.invoke(Method.java:372)
 D/MediaPlayer:     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1388)
 D/MediaPlayer:     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1183)
 D/MediaPlayer: Couldn't open file on client side, trying server side
10-24 12:25:26.665 6742-7036/com.company.app.android E/MediaPlayer: error (1, -2147483648)
10-24 12:25:26.685 6742-6742/com.company.app.android E/MediaPlayer: Error (1,-2147483648)
learner
  • 11,490
  • 26
  • 97
  • 169

1 Answers1

0

Well I cant comment and since there isn't any reference code to look at, here are few suggestions:

1) The solution works for Android version 4.0 or higher.

Initialize the MedialPlayer object inside the onSurfaceTextureAvailable() method and put it inside the try/catch block.

Parse the Uri. Since A Uri object is usually used to pass the reference of the content to a ContentProvider.

@Override
public void onSurfaceTextureAvailable(SurfaceTexture surfaceTexture, int i, int i2) {
    Surface surface = new Surface(surfaceTexture);

    try {
        mMediaPlayer= new MediaPlayer(); 
        // parse the URL path
        mMediaPlayer.setDataSource(getApplicationContext(), Uri.parse(URL_PATH));
        mMediaPlayer.setSurface(surface);
        mMediaPlayer.setLooping(true);

        mMediaPlayer.prepareAsync();


        mMediaPlayer.setOnBufferingUpdateListener(this);
        mMediaPlayer.setOnCompletionListener(this);
        mMediaPlayer.setOnVideoSizeChangedListener(this);
        mMediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);

        // Play video when the media source is ready for playback.
        mMediaPlayer.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
            @Override
            public void onPrepared(MediaPlayer mediaPlayer) {
                mediaPlayer.start();
            }
        });

    } catch (IllegalArgumentException e) {
        Log.d(TAG, e.getMessage());
    } catch (SecurityException e) {
        Log.d(TAG, e.getMessage());
    } catch (IllegalStateException e) {
        Log.d(TAG, e.getMessage());
    } catch (IOException e) {
        Log.d(TAG, e.getMessage());
    }
}

Also for streams prefer using prepareAsync(), since it returns immediately, rather than blocking until enough data has been buffered. call MediaPlayer.prepareAsync() method since you use constructor for creating MediaPlayer object.

Don't forget to do a memory cleanup once you are done playing video

@Override
protected void onDestroy() {
    super.onDestroy();
    if (mMediaPlayer != null) {
        mMediaPlayer.stop();
        mMediaPlayer.release();
        mMediaPlayer = null;
    }
}

Hope it helps!

Pavitra Kansara
  • 819
  • 8
  • 14
  • Sorry about the no code thing. It is here http://stackoverflow.com/questions/33288303/bufferqueue-has-been-abandoned-when-playing-video-with-textureview. Also I tried modifying to your way and still got the same errors. – learner Oct 24 '15 at 22:26