Hi there I'm working in my android app to run video from my local server XAMPP and I have placed my video in htdocs folder under my XAMPP server folder and I got this piece of code :
this is the .java file code
public class video extends Activity {
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.video1);
final VideoView vv = (VideoView) findViewById(R.id.vview);
MediaController mc = new MediaController(this);
vv.setMediaController(new MediaController(this));
vv.setVideoURI(Uri.parse("http://10.0.2.2/abc.MP4"));
vv.requestFocus();
vv.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
public void onPrepared(MediaPlayer mp) {
vv.start();
}
});
}
}
and here's my logcat errors
03-02 02:12:29.222: E/MediaPlayer(464): error (1, -2147483648)
03-02 02:12:29.242: E/MediaPlayer(464): start called in state 0
03-02 02:12:29.242: E/MediaPlayer(464): error (-38, 0)
03-02 02:12:29.252: E/MediaPlayer(464): Attempt to call getDuration without a valid mediaplayer
03-02 02:12:29.252: E/MediaPlayer(464): error (-38, 0)
03-02 02:12:29.322: E/MediaPlayer(464): Error (1,-2147483648)
03-02 02:12:29.742: E/MediaPlayer(464): Error (-38,0)
03-02 02:12:30.222: E/MediaPlayer(464): Error (-38,0)
When I click the button to direct me to video view layout where I should see my video playing I got a "black" blank screen for a moment then the screen changes to a white color for the lower have and black for the upper after that I receive the "this video can't be played" error msg three of them together
Related
I have uploaded a video in my recourses file in android studio and I want to play the video offline in my app my video is of 1 MB but when I run my app it throws an error
error (1, -2147483648)
and a pop up
shows up that Video can not be played.
E/SurfaceSyncer: Failed to find sync for id=0
E/MediaPlayerNative: error (1, -2147483648)
W/Parcel: Expecting binder but got null!
E/MediaPlayer: Error (1, -2147483648)
D/VideoView: Error: 1,-2147483648
This is my Main class code
package com.example.igea;
import...
public class MathsChap1 extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_maths_chap1);
Button bb = findViewById(R.id.ibk);
bb.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent i = new Intent( packageContext: MathsChap1.this, Maths.class);
startActivity(i);
}
});
VideoView v1 = findViewById(R.id.vv1);
v1.setVideoPath("android.resources://" + getPackageName() + "/" + R.raw.video1);
MediaController mc = new MediaController( context: this);
v1.setMediaController(mc);
mc.setAnchorView(v1);
v1.start();
}
}
Can someone please help me with this error?
You can use MediaPlayer
MediaPlayer mediaPlayer;
mediaPlayer = MediaPlayer.create(this, R.raw.your_video_file);
mediaPlayer.start();
i faced some problems when try to view video using VideoView. i always got message Can't play this video after that appears failed to connect
This is my url
rtsp://136.243.10.198:1935/xxx_vod/xx_1455171793.mp4?key=b1fbf3e6e6edcc2bb6c75f879edf8bf0
i got error on Log :
E/MediaPlayer: setDataSource: IOException! uri=rtsp://136.243.10.198:1935/xxx_vod/xx_1455171793.mp4?key=b1fbf3e6e6edcc2bb6c75f879edf8bf0
and
E/MediaPlayer: error (262, -1010)
My Code :
path = getActivity().getIntent().getStringExtra("path");
videoView.setMediaController(new MediaController(getActivity()));
videoView.setVideoPath(path);
videoView.requestFocus();
videoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
#Override
public void onPrepared(MediaPlayer mediaPlayer) {
mediaPlayer.start();
}
});
As the title suggests, I'm looking to play a small sound clip when a button is click - very basic. However, when I click the button the first time I get the following error:
08-01 15:01:58.547 18991-18991/? E/MediaPlayer﹕ Should have subtitle controller already set
08-01 15:02:01.030 18991-19008/za.co.site.app E/MediaPlayer﹕ error (1, -1010)
08-01 15:02:01.054 18991-18991/za.co.site.app E/MediaPlayer﹕ Error (1,-1010)
When I click the button again I get, the following error:
08-01 15:07:09.586 18991-18991/za.co.site.app E/MediaPlayer﹕ start called in state 0
08-01 15:07:09.586 18991-18991/za.co.site.app E/MediaPlayer﹕ error (-38, 0)
08-01 15:07:09.587 18991-18991/za.co.site.app E/MediaPlayer﹕ Error (-38,0)
I'm using a fragement. Here is the code:
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_main, container, false);
final Button b = (Button) view.findViewById(R.id.button1);
b.setEnabled(false);
final MediaPlayer mediaPlayer = MediaPlayer.create(getActivity(), R.raw.clip);
mediaPlayer.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
#Override
public void onPrepared(final MediaPlayer mp) {
b.setEnabled(true);
b.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
mp.start();
}
});
}
});
return view;
}
After reading around the first error is to do with Android not finding the file. However, the file is in a raw folder inside the res folder and android is definitely picking up the clip with R.raw.clip. By using the OnPreparedListener, this should stop the second error from occurring because the app caters for the clip to be ready before the button is pressed.
I'm not too sure when I'm doing wrong, thoughts?
You don't need to prepare if you are creating this way. Just call start().
This is because the file is local.
When using the Media player try to use mp3 files. The file I was using was a .wav file. The moment I made the file an mp3 file it worked.
Can anyone tell me how to use videoview to play mp4 url. I have written the code which is giving me error in my logcat as:
08-05 04:37:35.978: D/MediaPlayer(1693): getMetadata
08-05 04:37:37.918: E/MediaPlayer(1693): error (1, -19)
08-05 04:37:37.928: E/MediaPlayer(1693): Error (1,-19)
08-05 04:37:37.928: D/VideoView(1693): Error: 1,-19
I am using the videoview java code as:
public class VideoPlayerActivity extends Activity {
#SuppressLint("NewApi")
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.video_play);
VideoView videoView = (VideoView) findViewById(R.id.videoview_video);
MediaController mediaController = new MediaController(this);
mediaController.setAnchorView(videoView);
System.out.println(mediaController);
Uri video = Uri.parse("http://192.168.1.100/Android/jum.mp4");
videoView.setMediaController(mediaController);
videoView.setVideoURI(video);
System.out.println("View:"+videoView);
videoView.start();
}
}
I have made the video as H 264 compressed format but also i am not able to watch and listen the video
in the android app
Error in the android emulator is as shown below:
Did you set the internet permission in Manifest file?
Are you sure its http and not https ?
Are you running a version earlier than 3.1 ? If so, is the audio encoding through AACP?
These are some of the reasons that could give that error.
I have the source code of an app that plays .mp4 and I have to make it works with HLS.
The video and the sound are played but I have 2 problems ONLY WITH .m3u8 :
1) When seekTo() is activated (commentaries deleted) the sound is disabled and when I want to quit the player, it makes a long time to do and it makes crash the app.
2) setLooping doesn't work and return Error (-38,0), Attempt to perform seekTo in wrong
state: mPlayer=0x1e0380, mCurrentState=0
Note: those problems are just for .M3U8
Below code of the player :
private void playVideo() {
doCleanUp();
try {
// Create a new media player and set the listeners
mMediaPlayer = new MediaPlayer();
mMediaPlayer.setDataSource(mFilePath);
mMediaPlayer.setDisplay(mSurfaceHolder);
mMediaPlayer.prepare();
mMediaPlayer.start();
mMediaPlayer.setOnCompletionListener(this);
mMediaPlayer.setOnVideoSizeChangedListener(this);
mMediaPlayer.setOnPreparedListener(this);
//mMediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
//mMediaPlayer.seekTo(mResumePosition);
//mMediaPlayer.setLooping(true);
} catch (Exception e) {
Log.e(LOG_TAG, "error: " + e.getMessage(), e);
showErrorMessage(mErrorPlayingVideo);
// Toast.makeText(this, "Impossible de jouer la vidéo",
// 5000).show();
}
}
Logs when setLooping is activated under setDataSource() :
error (-38, 0)
prepareAsync called in wrong state 0
prepareAsync_l return error =-38
error: null
java.lang.IllegalStateException
at android.media.MediaPlayer.prepare(Native Method)
at fr.niji.broadpeak.activity.BroadpeakDemoPlayer.playVideo(BroadpeakDemoPlayer.java:409)
at fr.niji.broadpeak.activity.BroadpeakDemoPlayer.onRequestFinished(BroadpeakDemoPlayer.java:585)
at fr.niji.lib.dataproxy.service.DataManager.handleResult(DataManager.java:262)
at fr.niji.lib.dataproxy.service.DataManager.onRequestFinished(DataManager.java:292)
at fr.niji.lib.dataproxy.service.ServiceHelper.handleResult(ServiceHelper.java:297)
at fr.niji.lib.dataproxy.service.ServiceHelper$EvalReceiver.onReceiveResult(ServiceHelper.java:119)
at android.os.ResultReceiver$MyRunnable.run(ResultReceiver.java:43)
at android.os.Handler.handleCallback(Handler.java:587)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:132)
at android.app.ActivityThread.main(ActivityThread.java:4126)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:491)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:844)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:602)
at dalvik.system.NativeStart.main(Native Method)
and below the code :
Attempt to perform seekTo in wrong state: mPlayer=0x1e0380,
mCurrentState=0
error (-38, 0)
Error (-38,0)
Error (-38,0)
Attempt to perform seekTo in wrong state: mPlayer=0x1e0380, mCurrentState=0
Error (-38,0)
Error (-38,0)
Attempt to perform seekTo in wrong state: mPlayer=0x1e0380, mCurrentState=0
Ok I found the problem. When you use seekTo() with a .m3u8 file and the value between the parentheses is set to 0, it doesn't work so I added a condition into playBackVideo() method :
if (mResumePosition > 0) mMediaPlayer.seekTo(mResumePosition);
So mResumePosition will never be set to 0 and play at the beginning of the file. Also, i resolved the setLooping() problem, in
public void onCompletion(final MediaPlayer mediaPlayer)
I added mMediaPlayer.release(); playVideo();
and the looping works very well !
You need to check if it is the LIVE case. If Yes, Looping and seeking might not available.