I added a dependency compile "de.mrmaffen:vlc-android-sdk:3.0.0".
I wrote a class:
`
public class MainActivity extends Activity implements IVLCVout.Callback, LibVLC.HardwareAccelerationError {
public final static String TAG = "LibVLCAndroidSample/VideoActivity";
private String mFilePath;
// display surface
private SurfaceView mSurface;
private SurfaceHolder holder;
// media player
private LibVLC libvlc;
private MediaPlayer mMediaPlayer = null;
private int mVideoWidth;
private int mVideoHeight;
private final static int VideoSizeChanged = -1;
private String urlVideo = "rtmp://myserver.com:1935/rtmp/video1";
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Receive path to play from intent
mFilePath = urlVideo;
Log.d(TAG, "Playing back " + mFilePath);
mSurface = (SurfaceView) findViewById(R.id.surfaceview);
holder = mSurface.getHolder();
//holder.addCallback(this);
}
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
setSize(mVideoWidth, mVideoHeight);
}
@Override
protected void onResume() {
super.onResume();
createPlayer(mFilePath);
}
@Override
protected void onPause() {
super.onPause();
releasePlayer();
}
@Override
protected void onDestroy() {
super.onDestroy();
releasePlayer();
}
/*************
* Surface
*************/
private void setSize(int width, int height) {
mVideoWidth = width;
mVideoHeight = height;
if (mVideoWidth * mVideoHeight <= 1)
return;
if(holder == null || mSurface == null)
return;
// get screen size
int w = getWindow().getDecorView().getWidth();
int h = getWindow().getDecorView().getHeight();
// getWindow().getDecorView() doesn't always take orientation into
// account, we have to correct the values
boolean isPortrait = getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT;
if (w > h && isPortrait || w < h && !isPortrait) {
int i = w;
w = h;
h = i;
}
float videoAR = (float) mVideoWidth / (float) mVideoHeight;
float screenAR = (float) w / (float) h;
if (screenAR < videoAR)
h = (int) (w / videoAR);
else
w = (int) (h * videoAR);
// force surface buffer size
holder.setFixedSize(mVideoWidth, mVideoHeight);
// set display size
ViewGroup.LayoutParams lp = mSurface.getLayoutParams();
lp.width = w;
lp.height = h;
mSurface.setLayoutParams(lp);
mSurface.invalidate();
}
/*************
* Player
*************/
private void createPlayer(String media) {
releasePlayer();
try {
if (media.length() > 0) {
Toast toast = Toast.makeText(this, media, Toast.LENGTH_LONG);
toast.setGravity(Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL, 0,
0);
toast.show();
}
// Create LibVLC
// TODO: make this more robust, and sync with audio demo
ArrayList<String> options = new ArrayList<String>();
//options.add("--subsdec-encoding <encoding>");
options.add("--aout=opensles");
options.add("--audio-time-stretch"); // time stretching
options.add("-vvv"); // verbosity
libvlc = new LibVLC(options);
libvlc.setOnHardwareAccelerationError(this);
holder.setKeepScreenOn(true);
// Create media player
mMediaPlayer = new MediaPlayer(libvlc);
mMediaPlayer.setEventListener(mPlayerListener);
// Set up video output
final IVLCVout vout = mMediaPlayer.getVLCVout();
vout.setVideoView(mSurface);
//vout.setSubtitlesView(mSurfaceSubtitles);
vout.addCallback(this);
vout.attachViews();
Media m = new Media(libvlc, media);
mMediaPlayer.setMedia(m);
mMediaPlayer.play();
} catch (Exception e) {
Toast.makeText(this, "Error creating player!", Toast.LENGTH_LONG).show();
}
}
private void releasePlayer() {
if (libvlc == null)
return;
mMediaPlayer.stop();
final IVLCVout vout = mMediaPlayer.getVLCVout();
vout.removeCallback(this);
vout.detachViews();
holder = null;
libvlc.release();
libvlc = null;
mVideoWidth = 0;
mVideoHeight = 0;
}
private static class MyPlayerListener implements MediaPlayer.EventListener {
private WeakReference<MainActivity> mOwner;
public MyPlayerListener(MainActivity owner) {
mOwner = new WeakReference<MainActivity>(owner);
}
@Override
public void onEvent(MediaPlayer.Event event) {
MainActivity player = mOwner.get();
switch(event.type) {
case MediaPlayer.Event.EndReached:
Log.d(TAG, "MediaPlayerEndReached");
player.releasePlayer();
break;
case MediaPlayer.Event.Playing:
case MediaPlayer.Event.Paused:
case MediaPlayer.Event.Stopped:
default:
break;
}
}
}
/*************
* Events
*************/
private MediaPlayer.EventListener mPlayerListener = new MyPlayerListener(this);
@Override
public void onNewLayout(IVLCVout vlcVout, int width, int height, int visibleWidth, int visibleHeight, int sarNum, int sarDen) {
if (width * height == 0)
return;
// store video size
mVideoWidth = width;
mVideoHeight = height;
setSize(mVideoWidth, mVideoHeight);
}
@Override
public void onSurfacesCreated(IVLCVout vlcVout) {
}
@Override
public void onSurfacesDestroyed(IVLCVout vlcVout) {
}
@Override
public void eventHardwareAccelerationError() {
Log.e(TAG, "Error with hardware acceleration");
this.releasePlayer();
Toast.makeText(this, "Error with hardware acceleration", Toast.LENGTH_LONG).show();
}
}
`
I receive an error:
core access: VLC could not open the file "//rtmp://myserver.com:1935/rtmp/video1" (No such file or directory).
I added a dependency compile "de.mrmaffen:vlc-android-sdk:3.0.0". I wrote a class:
`
public class MainActivity extends Activity implements IVLCVout.Callback, LibVLC.HardwareAccelerationError { public final static String TAG = "LibVLCAndroidSample/VideoActivity";
}
` I receive an error:
why the link was a file?