Rtmp protocal Is not supporting in android - java

Can anyone help me rtmp url is not working where i tried lot of rtmp url but its not working and am using vitamio library...
if (!LibsChecker.checkVitamioLibs(this))
return;
setContentView(R.layout.activity_main);
mVideoView = (VideoView) findViewById(R.id.vitamio_videoView);
path = "rtmp://sonlifelivefs.fplive.net/sonlifelive-live/";
mVideoView.setVideoPath(path);
mVideoView.setMediaController(new MediaController(this));
mVideoView.requestFocus();
mVideoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
#Override
public void onPrepared(MediaPlayer mediaPlayer) {
mediaPlayer.setPlaybackSpeed(1.0f);
}
});
}
}

Related

How can i play google drive video in to android VideoView or in Iframe

I want to play video uploaded on google drive in android application VideoView or in iframe but getting problem to play video in android application.
Uri uri=Uri.parse("https://drive.google.com/open?id=XXXXXXXX/preview");
videoView.setMediaController(mediaController);
videoView.setVideoURI(uri);
videoView.requestFocus();
videoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
#Override
public void onPrepared(MediaPlayer mp) {
videoView.start();
}
});
play video in VideoView from google drive /preview url. same for iframe also

java.io.FileNotFoundException: No content provider:

i have problem to reproduce a video with videoView.setVideoPath();
in fact video doesn't reproduce..i don't know why. Video's path is correct.
This is my code:
public class MainActivity extends AppCompatActivity {
private VideoView videoView;
private int position = 0;
private MediaController mediaController;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
videoView = (VideoView) findViewById(R.id.videoView);
// Set the media controller buttons
if (mediaController == null) {
mediaController = new MediaController(MainActivity.this);
// Set the videoView that acts as the anchor for the MediaController.
mediaController.setAnchorView(videoView);
// Set MediaController for VideoView
videoView.setMediaController(mediaController);
}
try {
// ID of video file.
String videoUrl="https://www.youtube.com/watch?v=JHdmkP-nfsA";
videoView.setVideoPath(videoUrl);
} catch (Exception e) {
Log.e("Error", e.getMessage());
e.printStackTrace();
}
videoView.requestFocus();
// When the video file ready for playback.
videoView.setOnPreparedListener(new OnPreparedListener() {
public void onPrepared(MediaPlayer mediaPlayer) {
videoView.seekTo(position);
if (position == 0) {
videoView.start();
}
// When video Screen change size.
mediaPlayer.setOnVideoSizeChangedListener(new MediaPlayer.OnVideoSizeChangedListener() {
#Override
public void onVideoSizeChanged(MediaPlayer mp, int width, int height) {
// Re-Set the videoView that acts as the anchor for the MediaController
mediaController.setAnchorView(videoView);
}
});
}
});
}
}
Who can help me?
Thanks in advance everybody!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
LOGCAT:
Couldn't open https://www.youtube.com/watch?v=JHdmkP-nfsA: java.io.FileNotFoundException: No content provider: https://www.youtube.com/watch?v=JHdmkP-nfsA
10-29 12:27:28.419 25932-25932/com.example.marco.ud D/MediaPlayer: setDataSource IOException | SecurityException happend :
java.io.FileNotFoundException: No content provider: https://www.youtube.com/watch?v=JHdmkP-nfsA
at android.content.ContentResolver.openTypedAssetFileDescriptor(ContentResolver.java:1137)
at android.content.ContentResolver.openAssetFileDescriptor(ContentResolver.java:988)
at android.content.ContentResolver.openAssetFileDescriptor(ContentResolver.java:911)
at android.media.MediaPlayer.attemptDataSource(MediaPlayer.java:1102)
at android.media.MediaPlayer.setDataSource(MediaPlayer.java:1093)
at android.widget.VideoView.openVideo(VideoView.java:356)
at android.widget.VideoView.-wrap0(VideoView.java)
at android.widget.VideoView$7.surfaceCreated(VideoView.java:632)
at android.view.SurfaceView.updateWindow(SurfaceView.java:656)
at android.view.SurfaceView$3.onPreDraw(SurfaceView.java:172)
at android.view.ViewTreeObserver.dispatchOnPreDraw(ViewTreeObserver.java:1013)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2510)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1519)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:7113)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:927)
at android.view.Choreographer.doCallbacks(Choreographer.java:702)
at android.view.Choreographer.doFrame(Choreographer.java:638)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:913)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6780)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1496)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1386)
You can not play a YouTube video directly to the VideoView or ExoPlayer, for that, first you have to download the video then set the locale path of that video to the method VideoView.setVideoPath("path")
If you want to play only YouTube videos then use YouTube Android Player API, and if you only want to play other remote videos (.mp4, .ogg, .3gp etc.) then use the method VideoView.setVideoURI("uri").
Example-
String videoUrl = "http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4";
try {
// Start the MediaController
MediaController mediacontroller = new MediaController(this);
mediacontroller.setAnchorView(videoview);
// Get the URL from String videoUrl
Uri video = Uri.parse(videoUrl);
videoview.setMediaController(mediacontroller);
videoview.setVideoURI(video);
} catch (Exception e) {
Log.e("Error", e.getMessage());
e.printStackTrace();
}
videoview.setOnPreparedListener(new OnPreparedListener() {
public void onPrepared(MediaPlayer mp) {
videoview.start();
}
});
I recommend using ExoPlayer instead of VideoView:
app gradle:
implementation 'com.google.android.exoplayer:exoplayer:2.10.8'
layout xml:
<com.google.android.exoplayer2.ui.PlayerView
android:id="#+id/video_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerInParent="true" />
java code:
PlayerView videoView = findViewById(R.id.video_view);
SimpleExoPlayer player = ExoPlayerFactory.newSimpleInstance(this);
videoView.setPlayer(player);
// Produces DataSource instances through which media data is loaded.
DataSource.Factory dataSourceFactory = new DefaultDataSourceFactory(this, Util.getUserAgent(this, "yourApplicationName"));
// This is the MediaSource representing the media to be played.
MediaSource videoSource = new ProgressiveMediaSource.Factory(dataSourceFactory).createMediaSource(Uri.parse(fileEntity.getPath()));
// Prepare the player with the source.
player.prepare(videoSource);
player.setPlayWhenReady(true);
VideoView.setVideoPath requires a local path on the device. You should try setVideoURI instead if you want to play a remote MP4 or something else. VideoView Documentation
If you want to embed YouTube videos in your app, consider using the YouTube Android Player API or using something like a WebView
I had same issue but it was because of corporate proxy server. I used same app over my mobile internet and it started working. Hope it save someone's time
You are using VideoView which
Displays a video file. The VideoView class can load images from
various sources (such as resources or content providers).
You might want to try setVideoURI
Or : ExoPlayer if min SDK > 16
Or use SurfaceView :
SurfaceView surfaceView = (SurfaceView)findViewById(R.id.surfaceView);
SurfaceHolder surfaceHolder = surfaceView.getHolder();
surfaceHolder.addCallback(new SurfaceHolder.Callback() {
#Override
public void surfaceCreated(SurfaceHolder surfaceHolder) {
mediaPlayer.setDataSource(STREAM_URL);
mediaPlayer.setDisplay(surfaceHolder);
mediaPlayer.start();
}
Ref : https://developer.android.com/reference/android/widget/VideoView.html

Play Video Using External Media Player in Android

Well, I've used VideoView to play my Video. It only support .mp4 format(Correct me if I'm wrong), I need to play .flv video. I've MX Player/VLC player installed on my Android phone. How do I load the list of available Media Players when I click Play Video Button in my Activity.
Below is the code I've written using Video View, if it helps
public void onClick(View v) {
File root = Environment.getExternalStorageDirectory();
String externalFilesDir = getExternalFilesDir(null).toString();
String videoResource = externalFilesDir +"/" + "VID_20160115_215637181.mp4";
mediaController.setAnchorView(videoView);
videoView.setMediaController(mediaController);
videoView.setVideoPath(videoResource);
videoView.requestFocus();
videoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
#Override
public void onPrepared(MediaPlayer mp) {
videoView.seekTo(0);
videoView.start();
}
});
}
If You want to play video in some other player, you can use ACTION_VIEW intent
Example in this question: Android intent for playing video?

Problems rendering video only in Samnsung GT-I8260 using SurfaceView. IOException: Prepare failed.: status=0x1

I'm developing an app that uses a ViewPager with one video in each page. Everything works well in every smartphone but it doesn't work in Samnsung GT-I8260 with Android 4.1.2
So in this smartphone, when I compile it returns IOException: Prepare failed.: status=0x1 and it points to mMediaPlayer.prepare();
Now the code is the next:
//First of all I initilize MediaPlayer and I handle the Callback method for SurfaceView
mMediaPlayer = new MediaPlayer();
mSurfaceView.getHolder().addCallback(new SurfaceHolder.Callback() {
#Override
public void surfaceDestroyed(SurfaceHolder holder) {
mMediaPlayer.release();
}
#Override
public void surfaceCreated(SurfaceHolder holder) {
holder.setSizeFromLayout();
playVideoDelay();
}
#Override
public void surfaceChanged(SurfaceHolder holder,
int format, int width, int height) {
}
});
//The app plays the first video with the next method
private void playVideoDelay() {
try {
Uri path = Uri.parse("android.resource://com.casabioclimatica/raw/"+mVideoId);
mMediaPlayer.reset();
mMediaPlayer.setDataSource( mActivity, path);
mMediaPlayer.setDisplay(mSurfaceView.getHolder());
mMediaPlayer.prepare();
if (Build.VERSION.SDK_INT >= 16)
mMediaPlayer
.setVideoScalingMode(MediaPlayer.VIDEO_SCALING_MODE_SCALE_TO_FIT_WITH_CROPPING);
mMediaPlayer.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
#Override
public void onPrepared(MediaPlayer mp) {
mp.start();
}
});
// fis = new FileInputStream(new File(path.getPath()));
//mMediaPlayer.setDataSource(fis.getFD());
} catch (Exception e) {
e.printStackTrace();
}
}
//When ViewPager changes it pages I call this method:
public void playVideoDelay(int videoId) {
try {
Uri path = Uri.parse("android.resource://com.casabioclimatica/raw/"+videoId);
mMediaPlayer.reset();
mMediaPlayer.setDataSource( mActivity, path);
mMediaPlayer.setDisplay(mSurfaceView.getHolder());
mMediaPlayer.prepare();
if (Build.VERSION.SDK_INT >= 16)
mMediaPlayer
.setVideoScalingMode(MediaPlayer.VIDEO_SCALING_MODE_SCALE_TO_FIT_WITH_CROPPING);
mMediaPlayer.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
#Override
public void onPrepared(MediaPlayer mp) {
mp.start();
}
});
} catch (Exception e) {
e.printStackTrace();
}
}
Hope somebody has had something similar and knows the proper solution!
Thanks!
After a lot of code changes,I have found the problem in this smartphone, this is because of the maximum resolution. In this case it has 800 x 480 px and I was using 1080 x 800, it was too much and the Dalvik machine interprets that case like this file doesn't exist or doesn't work. I have changed the high and width size of the file and it works like charm!
So for any similar case: Pay attention to your maximum screen supported resolution and try to use this size to avoid any strange error when you render a video.
Hope it helps!

Can't play this video. Android videoView mp4 recorded by android device

I've looked for existing potential solutions with other formats and those still responds with mentioned error.
Finally, recorded the video with the same device and used it as a resource for this app and it still doesn't work.
Devices: SGS2, lenovo a820
Video type: MPEG-4 video (video/mp4)
videoView = (VideoView)findViewById(R.id.videoView);
videoView.setVideoPath("android.resource://raw/sample.mp4");
videoView.start();
Please refer below code snippet...problem was with the path declaration..
String uriPath = "android.resource://"+getPackageName()+"/"+R.raw.aha_hands_only_cpr_english;
Uri uri = Uri.parse(uriPath);
mVideoView.setVideoURI(uri);
Thats it...
I tried everything mentioned before but it turns out that internet permission is needed to play a mp4 file.
<uses-permission android:name="android.permission.INTERNET" />
try following code..
videoView = (VideoView)this.findViewById(R.id.videoView);
String path = "android.resource://" + getPackageName() + "/" + R.raw.video_file;
MediaController mc = new MediaController(this);
videoView.setMediaController(mc);
videoView.start();
public class videoplayer extends Activity {
private static final String Videos_URL = "*your URI*";
private VideoView myVideoView;
private int position = 0;
private ProgressDialog progressDialog;
private MediaController mediaControls;
#Override
protected void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Get the layout from video_main.xml
setContentView(R.layout.activity_main);
if (mediaControls == null) {
mediaControls = new MediaController(this);
}
// Find your VideoView in your video_main.xml layout
myVideoView = (VideoView) findViewById(R.id.videoView);
// Create a progressbar
progressDialog = new ProgressDialog(this);
// Set progressbar title
progressDialog.setTitle("ABCDEFGH");
// Set progressbar message
progressDialog.setMessage("Loading...");
progressDialog.setCancelable(false);
// Show progressbar
progressDialog.show();
try {
Uri video = Uri.parse(Videos_URL);
myVideoView.setVideoURI(video);
myVideoView.setMediaController(mediaControls);
} catch (Exception e) {
Log.e("Error", e.getMessage());
e.printStackTrace();
}
myVideoView.requestFocus();
myVideoView.setOnPreparedListener(new OnPreparedListener() {
// Close the progress bar and play the video
public void onPrepared(MediaPlayer mp) {
progressDialog.dismiss();
myVideoView.seekTo(position);
if (position == 0) {
myVideoView.start();
} else {
myVideoView.pause();
}
}
});
}
#Override
public void onSaveInstanceState(Bundle savedInstanceState) {
super.onSaveInstanceState(savedInstanceState);
savedInstanceState.putInt("Position", myVideoView.getCurrentPosition());
myVideoView.pause();
}
#Override
public void onRestoreInstanceState(Bundle savedInstanceState) {
super.onRestoreInstanceState(savedInstanceState);
position = savedInstanceState.getInt("Position");
myVideoView.seekTo(position);
}
}
Be sure that the decoder (target sdk) supports the video format you are using. You can use VLC Player to convert video format to the desired one. In my case, I converted the MP4 to WebM file and load it in the VideoView.
Here is how you get the file path and play your video.
String path = "android.resource://" + getPackageName() + "/" + R.raw.sample;
VideoView videoView = (VideoView)findViewById(R.id.videoView);
videoView.setVideoURI(Uri.parse(path));
videoView.start()
Source:
Video format and codec support
https://developer.android.com/guide/topics/media/media-formats.html
For Lenovo a820 ,below is need :
- MP4/WMV/H.264/H.263 player
- MP3/WAV/WMA/eAAC+ player
make sure that ur video fits in above codec format.
Just Replace your code with this code and it will be working:
VideoView videoView = findViewById(R.id.videoView);
videoView.setVideoPath("android.resource://" + getPackageName() + "/" + R.raw.sample);
videoView.start();
I think the issue is with the device on which we try to play video, sometimes it doesn't support.
I tried running it on Linux emulatoe
Try this following code it works..........
VideoView videoView=(VideoView)findViewById(R.id.videoView);
videoView.setVideoPath("android.resource://"+getPackageName()+"/"+R.raw.videoname;
videoView.start();

Categories

Resources