0

I need to be able to animate videos in and out of the view, so I'm using a TextureView. I'm streaming it from a Node.js server (using res.sendFile() from express). However, when the video gets played, I get this instead of the video.

enter image description here

Here's my code. I've googled for hours and have no idea what's going on. VideoView plays the video just fine. I'm not terribly experienced in VideoStreaming, so hopefully it's something obvious that I just don't know to look for.

package com.spectiv.displayer;

import android.animation.LayoutTransition;
import android.app.Application;
import android.content.Context;
import android.graphics.SurfaceTexture;
import android.media.AudioManager;
import android.media.MediaPlayer;
import android.net.Uri;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.Surface;
import android.view.SurfaceHolder;
import android.view.TextureView;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.AlphaAnimation;
import android.webkit.WebChromeClient;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.FrameLayout;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.VideoView;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.Inet4Address;
import java.net.InetAddress;
import java.net.MalformedURLException;
import java.net.NetworkInterface;
import java.net.SocketException;
import java.net.URL;
import java.util.Enumeration;
import java.util.Objects;
import android.os.Handler;

/**
 * An example full-screen activity that shows and hides the system UI (i.e.
 * status bar and navigation/system bar) with user interaction.
 */
public class DisplayerActivity extends AppCompatActivity implements TextureView.SurfaceTextureListener{
    private Handler mainHandler = new Handler();
    private FrameLayout layout;
    private TextureView textureView;
    private MediaPlayer mMediaPlayer;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_displayer);
        layout = (FrameLayout) findViewById(R.id.rootLayout);
        textureView = new TextureView(this);
        textureView.setSurfaceTextureListener(this);
        currentView = textureView;
        layout.addView(textureView);
    }

    //  Trying a texture view with videos
    public void onSurfaceTextureAvailable(SurfaceTexture surface, int width, int height) {
        Surface s = new Surface(surface);
        try {
            mMediaPlayer= new MediaPlayer();
            mMediaPlayer.setSurface(s);
            mMediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
            mMediaPlayer.setDataSource("http://192.168.1.211:6543/video");
            mMediaPlayer.prepareAsync();
            mMediaPlayer.setOnBufferingUpdateListener(new MediaPlayer.OnBufferingUpdateListener() {
                @Override
                public void onBufferingUpdate(MediaPlayer mp, int percent) {
                    speak("Buffering");
                }
            });
            mMediaPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
                @Override
                public void onCompletion(MediaPlayer mp) {
                    speak("Video is Complete!");
                }
            });
            mMediaPlayer.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
                @Override
                public void onPrepared(MediaPlayer mp) {
                    mMediaPlayer.start();
                }
            });
            mMediaPlayer.setOnVideoSizeChangedListener(new MediaPlayer.OnVideoSizeChangedListener() {
                @Override
                public void onVideoSizeChanged(MediaPlayer mp, int width, int height) {
                    // Nothing;
                }
            });
        } catch (IllegalArgumentException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public void onSurfaceTextureSizeChanged(SurfaceTexture surface, int width, int height) {
        // Ignored
    }

    public boolean onSurfaceTextureDestroyed(SurfaceTexture surface) {
        mMediaPlayer.stop();
        mMediaPlayer.release();
        return true;
    }

    public void onSurfaceTextureUpdated(SurfaceTexture surface) {
        // Invoked every time there's a new Camera preview frame
    }
}
Euroclydon37
  • 667
  • 7
  • 20
  • Have you tried it with a different working streaming video, just in case there is an issue on the server side? Also do you have any log output? – Mick Feb 16 '17 at 11:46
  • This same video streaming from the same node.js server works perfectly with a VideoView, so I hadn't tried different video. I try that and see what happens. And I don't know why I didn't think to post the log. I'll add it to the question when I get to work. – Euroclydon37 Feb 16 '17 at 12:25

0 Answers0