Android MediaPlayer with SurfaceView Fails on Prepare() Method - android

I am trying to build a video player using surface view and media player. My data source is an online video and I have enabled internet permission in manifest.
However, the video does not pay but throws a warning about prepare method without any hint at what the problem is like below:
W/System.err: at android.media.MediaPlayer._prepare(Native Method)
at android.media.MediaPlayer.prepare(MediaPlayer.java:1188)
at in.sashi.androidvideoplayer.MainActivity.surfaceCreated(MainActivity.java:64)
here's my code for this purpose:
public class MainActivity extends AppCompatActivity implements SurfaceHolder.Callback, MediaPlayer.OnPreparedListener, View.OnClickListener {
private static final String TAG = MainActivity.class.getSimpleName();
private SurfaceView surfaceView;
private ImageView playIV, backIV;
private TextView videoNameTV;
private MediaPlayer mediaPlayer;
private SurfaceHolder holder;
// private static final String VIDEO_URL = "https://www.youtube.com/watch?v=vEVd0QMjCc8";
private static final String VIDEO_URL = "http://mic.duytan.edu.vn:83/FINAL.mp4";
private static final String VIDEO_NAME = "FALL HARDER | BASKETBALL MOTIVATION";
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
init();
}
private void init() {
surfaceView = findViewById(R.id.surfsceView);
playIV = findViewById(R.id.playIV);
backIV = findViewById(R.id.backIV);
videoNameTV = findViewById(R.id.videoNameTV);
videoNameTV.setText(VIDEO_NAME);
backIV.setOnClickListener(this);
playIV.setOnClickListener(this);
holder = surfaceView.getHolder();
holder.addCallback(this);
surfaceView.setKeepScreenOn(true);
mediaPlayer = new MediaPlayer();
}
#Override
public void surfaceCreated(SurfaceHolder holder) {
mediaPlayer.setDisplay(holder);
try {
mediaPlayer.setDataSource(VIDEO_URL);
mediaPlayer.prepare();
mediaPlayer.setOnPreparedListener(this);
mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
} catch (IOException e) {
e.printStackTrace();
}
}
#Override
public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
}
#Override
public void surfaceDestroyed(SurfaceHolder holder) {
}
#Override
public void onPrepared(MediaPlayer mp) {
mp.start();
}
#Override
public void onClick(View v) {
switch (v.getId()){
case R.id.backIV:
onBackPressed();
break;
case R.id.playIV:
if (mediaPlayer.isPlaying()){
Log.d(TAG, "Pause Clicked");
mediaPlayer.pause();
playIV.setImageResource(R.drawable.play);
} else {
Log.d(TAG, "Play Clicked");
mediaPlayer.start();
playIV.setImageResource(R.drawable.pause);
}
break;
}
}
#Override
protected void onPause() {
super.onPause();
collect();
}
private void collect() {
if (mediaPlayer != null){
mediaPlayer.release();
mediaPlayer = null;
}
}
}
Can anyone help me to figure this out? Thanks.

Use mediaplayer object which is being defined globally.
#Override
public void onPrepared(MediaPlayer mp) {
mediaPlayer.start();
}

How about this?
#Override
public void surfaceCreated(SurfaceHolder holder) {
mediaPlayer.setDisplay(holder);
try {
mediaPlayer.setDataSource(VIDEO_URL);
mediaPlayer.setOnPreparedListener(this);
mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
mediaPlayer.prepareAsync();
} catch (IOException e) {
e.printStackTrace();
}
}

Related

wowza cloud live streaming is not working

I'm using Wowza streaming cloud it works fine using HLS link on the web but an android device not working on the web view.can you anyone me how its work.
And rtsp live link also not working on android device
public class AnotherOne extends AppCompatActivity implements
SurfaceHolder.Callback, MediaPlayer.OnPreparedListener{
private String Downloadurl;
private int playminute;
private SurfaceView mSurfaceView;
private MediaPlayer mMediaPlayer;
private SurfaceHolder mSurfaceHolder;
ProgressBar p_bar;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_another_one);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
View decorView = getWindow().getDecorView();
int uiOptions = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_FULLSCREEN;
decorView.setSystemUiVisibility(uiOptions);
Downloadurl = "https://7c6ad8.entrypoint.cloud.wowza.com/app-04be/ngrp:f23a3900_all/playlist.m3u8";
// Description = getIntent().getStringExtra("Description");
Log.e("kanish","Download Url inside player:"+Downloadurl);
mSurfaceView = (SurfaceView) findViewById(R.id.surfaceView);
mSurfaceHolder = mSurfaceView.getHolder();
mSurfaceHolder.addCallback(this);
}
#Override
public void surfaceCreated(SurfaceHolder holder) {
// p_bar.setVisibility(View.VISIBLE);
mMediaPlayer = new MediaPlayer();
mMediaPlayer.setDisplay(mSurfaceHolder);
try {
mMediaPlayer.setDataSource(Downloadurl);
mMediaPlayer.prepare();
mMediaPlayer.setOnPreparedListener(AnotherOne.this);
//mMediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
} catch (IOException e) {
e.printStackTrace();
}
}
#Override
public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
}
#Override
public void surfaceDestroyed(SurfaceHolder holder) {
}
#Override
public void onBackPressed() {
super.onBackPressed();
}
#Override
public void onPrepared(MediaPlayer mp) {
//p_bar.setVisibility(View.GONE);
mMediaPlayer.start();
}
#Override
protected void onPause() {
super.onPause();
releaseMediaPlayer();
}
#Override
protected void onDestroy() {
super.onDestroy();
releaseMediaPlayer();
}
private void releaseMediaPlayer() {
if (mMediaPlayer != null) {
mMediaPlayer.release();
mMediaPlayer = null;
}
}
}
you need to declare a view to render video View and
You need to use Media Player Api Provided by Android to Stream m3u8.it is pretty Simple to play Live content follow this code.
public class PlayerActivity extends AppCompatActivity implements
SurfaceHolder.Callback, MediaPlayer.OnPreparedListener {
private String Downloadurl;
private int playminute;
private SurfaceView mSurfaceView;
private MediaPlayer mMediaPlayer;
private SurfaceHolder mSurfaceHolder;
ProgressBar p_bar;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.player);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
View decorView = getWindow().getDecorView();
int uiOptions = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_FULLSCREEN;
decorView.setSystemUiVisibility(uiOptions);
Downloadurl = "YOUR M3U8 URL";
// Description = getIntent().getStringExtra("Description");
Log.e("kanish","Download Url inside player:"+Downloadurl);
mSurfaceView = (SurfaceView) findViewById(R.id.surface_view);
mSurfaceHolder = mSurfaceView.getHolder();
mSurfaceHolder.addCallback(PlayerActivity.this);
}
#Override
public void surfaceCreated(SurfaceHolder holder) {
p_bar.setVisibility(View.VISIBLE);
mMediaPlayer = new MediaPlayer();
mMediaPlayer.setDisplay(mSurfaceHolder);
try {
mMediaPlayer.setDataSource(Downloadurl);
mMediaPlayer.prepare();
mMediaPlayer.setOnPreparedListener(PlayerActivity.this);
//mMediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
} catch (IOException e) {
e.printStackTrace();
}
}
#Override
public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
}
#Override
public void surfaceDestroyed(SurfaceHolder holder) {
}
#Override
public void onBackPressed() {
super.onBackPressed();
}
#Override
public void onPrepared(MediaPlayer mp) {
p_bar.setVisibility(View.GONE);
mMediaPlayer.start();
}
#Override
protected void onPause() {
super.onPause();
releaseMediaPlayer();
}
#Override
protected void onDestroy() {
super.onDestroy();
releaseMediaPlayer();
}
private void releaseMediaPlayer() {
if (mMediaPlayer != null) {
mMediaPlayer.release();
mMediaPlayer = null;
}
}
}
Let me Know if it helps.

MediaPlayer's subtitle feature is not working (SRT file)

I am trying to show the subtitle from the .srt file. (For Android 4.1+)
Both mp4 file and srt file exist in the device.
public class MainActivity extends Activity implements SurfaceHolder.Callback, OnPreparedListener{
MediaPlayer mediaPlayer;
SurfaceHolder surfaceHolder;
SurfaceView playerSurfaceView;
TextView tv_subtitle;
String videoSrc = Environment.getExternalStorageDirectory().getPath() + "/video.mp4";
String subTitleSrc = Environment.getExternalStorageDirectory().getPath() + "/sub.srt";
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
playerSurfaceView = (SurfaceView)findViewById(R.id.playersurface);
tv_subtitle = (TextView)findViewById(R.id.tv_subtitle);
surfaceHolder = playerSurfaceView.getHolder();
surfaceHolder.addCallback(this);
}
#Override
public void surfaceChanged(SurfaceHolder arg0, int arg1, int arg2, int arg3) {
}
#Override
public void surfaceCreated(SurfaceHolder arg0) {
try {
mediaPlayer = new MediaPlayer();
mediaPlayer.setDisplay(surfaceHolder);
mediaPlayer.setDataSource(videoSrc);
mediaPlayer.setOnTimedTextListener(new MediaPlayer.OnTimedTextListener() {
#Override
public void onTimedText(final MediaPlayer mediaPlayer, final TimedText timedText) {
if (timedText != null) {
Log.d("test", "subtitle: " + timedText.getText());
}
}
});
mediaPlayer.addTimedTextSource(subTitleSrc, MediaPlayer.MEDIA_MIMETYPE_TEXT_SUBRIP);
mediaPlayer.prepare();
mediaPlayer.setOnPreparedListener(this);
mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
} catch (Exception e) {
}
}
#Override
public void surfaceDestroyed(SurfaceHolder arg0) {
}
#Override
public void onPrepared(MediaPlayer mp) {
mediaPlayer.start();
}
}
Layout:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<SurfaceView
android:id="#+id/playersurface"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
<TextView
android:layout_gravity="center"
android:id="#+id/tv_subtitle"
android:textColor="#android:color/holo_red_dark"
android:textSize="20sp"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
OnTimedTextListener is not being called. My Target SDK is 22 and my devices are above Android 4.1
Am I missing anything?
I found the Answer.
Credit: Looking for a working example of addTimedTextSource for adding subtitle to a video from an .srt file in Android 4.1
mediaPlayer.selectTrack() method was missing in my code.
Here's the complete code:
public class MainActivity extends Activity implements SurfaceHolder.Callback, OnPreparedListener{
MediaPlayer mediaPlayer;
SurfaceHolder surfaceHolder;
SurfaceView playerSurfaceView;
TextView tv_subtitle;
String videoSrc = Environment.getExternalStorageDirectory().getPath() + "/video.mp4";
String subTitleSrc = Environment.getExternalStorageDirectory().getPath() + "/sub.srt";
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
playerSurfaceView = (SurfaceView)findViewById(R.id.playersurface);
tv_subtitle = (TextView)findViewById(R.id.tv_subtitle);
surfaceHolder = playerSurfaceView.getHolder();
surfaceHolder.addCallback(this);
}
#Override
public void surfaceChanged(SurfaceHolder arg0, int arg1, int arg2, int arg3) {
}
#Override
public void surfaceCreated(SurfaceHolder arg0) {
try {
mediaPlayer = new MediaPlayer();
mediaPlayer.setDisplay(surfaceHolder);
mediaPlayer.setDataSource(videoSrc);
mediaPlayer.setOnPreparedListener(this);
mediaPlayer.prepare();
mediaPlayer.addTimedTextSource(subTitleSrc, MediaPlayer.MEDIA_MIMETYPE_TEXT_SUBRIP);
int textTrackIndex = findTrackIndexFor(
MediaPlayer.TrackInfo.MEDIA_TRACK_TYPE_TIMEDTEXT, mediaPlayer.getTrackInfo());
if (textTrackIndex >= 0) {
mediaPlayer.selectTrack(textTrackIndex);
} else {
Log.w("test", "Cannot find text track!");
}
mediaPlayer.setOnTimedTextListener(new MediaPlayer.OnTimedTextListener() {
#Override
public void onTimedText(final MediaPlayer mediaPlayer, final TimedText timedText) {
if (timedText != null) {
Log.d("test", "subtitle: " + timedText.getText());
}
}
});
mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
} catch (Exception e) {
}
}
private int findTrackIndexFor(int mediaTrackType, MediaPlayer.TrackInfo[] trackInfo) {
int index = -1;
for (int i = 0; i < trackInfo.length; i++) {
if (trackInfo[i].getTrackType() == mediaTrackType) {
return i;
}
}
return index;
}
#Override
public void surfaceDestroyed(SurfaceHolder arg0) {
}
#Override
public void onPrepared(MediaPlayer mp) {
mediaPlayer.start();
}
}

How to prepare mediaplayer in android while another playing?

I using MediaPlayerto play video from http stream is any solution to prepare second media player with another http url while first one still playing?
I want to play two videos without black screen between them, when first one end second start immediately.
Here is my code:
public class VideoActivity extends Activity implements SurfaceHolder.Callback {
private MediaPlayer mediaPlayer;
private SurfaceHolder surfaceHolder;
private SurfaceView playerSurfaceView;
private String videoSrc = "http://192.168.1.101:8090/api/video/";
private String android_id;
private MediaPlayer next;
private static boolean firstCall = true;
private String secondVideoSrc = "http://192.168.1.101:8090/api/secondvideo/";
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_video);
playerSurfaceView = (SurfaceView)findViewById(R.id.playersurface);
surfaceHolder = playerSurfaceView.getHolder();
surfaceHolder.addCallback(this);
GetDeviceId();
videoSrc += android_id;
secondVideoSrc += android_id;
}
#Override
public void surfaceCreated(SurfaceHolder holder) {
prepareVideoPlayer();
}
#Override
public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
}
#Override
public void surfaceDestroyed(SurfaceHolder holder) {
}
private void GetDeviceId() {
android_id = Settings.Secure.getString(getBaseContext().getContentResolver(),
Settings.Secure.ANDROID_ID);
}
private void prepareVideoPlayer() {
try {
mediaPlayer = new MediaPlayer();
mediaPlayer.setDisplay(surfaceHolder);
mediaPlayer.setDataSource(this, Uri.parse(videoSrc));
mediaPlayer.setScreenOnWhilePlaying(true);
mediaPlayer.prepareAsync();
mediaPlayer.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
#Override
public void onPrepared(MediaPlayer mp) {
if(firstCall) {
mediaPlayer.start();
firstCall = false;
}
new AsyncPrepareNext().execute();
}
});
mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
mediaPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
#Override
public void onCompletion(MediaPlayer mp) {
next.start();
}
});
}
catch(Exception ex) {
}
}
private void prepareNext() {
try {
next = new MediaPlayer();
next.setDisplay(surfaceHolder);
next.setDataSource(this, Uri.parse(secondVideoSrc));
next.setScreenOnWhilePlaying(true);
next.prepareAsync();
next.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
#Override
public void onPrepared(MediaPlayer mp) {
}
});
next.setAudioStreamType(AudioManager.STREAM_MUSIC);
next.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
#Override
public void onCompletion(MediaPlayer mp) {
}
});
}
catch(Exception ex) {
}
}
private class AsyncPrepareNext extends AsyncTask<Void,Void,Void> {
#Override
protected Void doInBackground(Void... params) {
prepareNext();
return null;
}
}
}
When i run this first video starts for 2 or 3 seconds and then stop with some errors like media server died, audio flinger died, error (100,0), error (38,0)
You'll probably need to implement the OnPreparedListener() and OnCompletedListener() to accomplish this and you might need 2 media players for it as well.
#Override
public void onPrepared(MediaPlayer mp){
// Set Video Source for second video
mp.setDataSource(path);
// Prepare second video
mp.prepareAsync();
}
#Override
public void onCompletion(MediaPlayer mp){
// Start second video here
mp.start();
}
and set them like this:
mediaPlayer.setOnPreparedListener(new OnPreparedListener());
mediaPlayer.setOnCompletedListener(new OnCompletionListener());

Android play video in surfaceview NullPointerException

I try to play video in surfaceview. I use Fragment (extends Fragment) and I have NullPointerException. I have no idea what am I doing wrong. First time I used Activity and in Activity project worked perfect but I use Fragment and I have error
This is a my source
public class Layout1 extends Fragment implements OnBufferingUpdateListener,
OnCompletionListener, OnPreparedListener, OnVideoSizeChangedListener,
SurfaceHolder.Callback, MediaPlayerControl {
MediaPlayer mMediaPlayer;
SurfaceView mSurfaceView;
SurfaceHolder holder;
String video = "http://www.pocketjourney.com/downloads/pj/video/famous.3gp";
MediaController mcontroller;
Handler handler;
String videoUrl;
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_layout1, null);
SurfaceView v = (SurfaceView) view
.findViewById(R.id.screen_tutorial_video_surface);
handler = new Handler();
holder = v.getHolder();
holder.addCallback(this);
playVideo();
return view;
}
private void playVideo() {
try {
mcontroller = new MediaController(getActivity());
mcontroller.setVisibility(View.INVISIBLE);
mMediaPlayer = MediaPlayer.create(getActivity(), Uri.parse(video));
mMediaPlayer.setOnBufferingUpdateListener(this);
mMediaPlayer.setOnCompletionListener(this);
mMediaPlayer.setOnPreparedListener(this);
mMediaPlayer.setScreenOnWhilePlaying(true);
mMediaPlayer.setOnVideoSizeChangedListener(this);
mMediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
} catch (Exception e) {
e.printStackTrace();
}
}
#Override
public void surfaceChanged(SurfaceHolder arg0, int arg1, int arg2, int arg3) {
}
#Override
public void surfaceCreated(SurfaceHolder arg0) {
mMediaPlayer.setDisplay(holder);
try {
// progressDialog.dismiss();
mMediaPlayer.start();
} catch (IllegalStateException e) {
e.printStackTrace();
}
}
#Override
public void surfaceDestroyed(SurfaceHolder arg0) {
}
#Override
public void onVideoSizeChanged(MediaPlayer mp, int width, int height) {
// TODO Auto-generated method stub
}
#Override
public void onPrepared(MediaPlayer mp) {
// mcontroller.setMediaPlayer(this);
// mcontroller
// .setAnchorView(findViewById(R.id.screen_tutorial_video_surface));
// mcontroller.setEnabled(true);
//
// handler.post(new Runnable() {
// public void run() {
// mcontroller.show();
// }
// });
}
#Override
public void onCompletion(MediaPlayer mp) {
}
#Override
public void onBufferingUpdate(MediaPlayer mp, int percent) {
}
public void start() {
mMediaPlayer.start();
}
public void pause() {
mMediaPlayer.pause();
}
public int getDuration() {
return mMediaPlayer.getDuration();
}
public int getCurrentPosition() {
return mMediaPlayer.getCurrentPosition();
}
public void seekTo(int i) {
mMediaPlayer.seekTo(1);
}
public boolean isPlaying() {
return mMediaPlayer.isPlaying();
}
public int getBufferPercentage() {
return 0;
}
public boolean canPause() {
return true;
}
public boolean canSeekBackward() {
return true;
}
public boolean canSeekForward() {
return true;
}
}
Error log
It seems that onSurfaceCreated is called before playVideo(). Initialize your mMediaPlayer (and handler too by the way) in Fragment's onCreate().
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
handler = new Handler();
playVideo();
}
private void playVideo() {
mcontroller = new MediaController(getActivity());
mcontroller.setVisibility(View.INVISIBLE);
mMediaPlayer = MediaPlayer.create(getActivity(), Uri.parse(video));
// implement a fallback mechanism if it fails, for example if no internet or 404
if (mMediaPlayer == null) {
Log.w("Layout1", "Faileded to create MediaPlayer");
return;
}
mMediaPlayer.setOnBufferingUpdateListener(this);
mMediaPlayer.setOnCompletionListener(this);
mMediaPlayer.setOnPreparedListener(this);
mMediaPlayer.setScreenOnWhilePlaying(true);
mMediaPlayer.setOnVideoSizeChangedListener(this);
mMediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_layout1, null);
SurfaceView v = (SurfaceView) view
.findViewById(R.id.screen_tutorial_video_surface);
v.getHolder().addCallback(this);
return view;
}
#Override
public void surfaceCreated(SurfaceHolder arg0) {
if (mMediaPlayer == null) {
// implement a fallback mechanism if it fails, for example if no internet or 404
Log.w("Layout1", "MediaPlayer was not created");
return;
}
// the holder reference is already passed as arg0 here
mMediaPlayer.setDisplay(arg0);
try {
// progressDialog.dismiss();
mMediaPlayer.start();
} catch (IllegalStateException e) {
e.printStackTrace();
}
}
After you removed catch (Exception e) in playVideo()
If you looked closely in logs you could have seen
Permission failure: android.permission.INTERNET from uid=10052 pid=1129
Request requires android.permission.INTERNET
Unable to create media player
create failed:
java.io.IOException: setDataSource failed.: status=0x80000000
Thus you also need to add permission
<uses-permission android:name="android.permission.INTERNET"/>
If it wasn't for the project you've attached we would never knew.

MediaPlayer.setDisplay() in android

I am creating a video player using MediaPlayer class in android. I set a SurfaceHolder in MediaPlayer.setDisplay(), it shows video successfully but when this activity resumed again then no video is diplayed. So what is wrong ??
The Code is:
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.main);
player = new MediaPlayer();
surface = (SurfaceView)findViewById(R.id.surface);
surface.setOnClickListener(new OnClickListener()
{
#Override
public void onClick(View v)
{
VideoDemo.this.startActivity(new Intent(VideoDemo.this, AnotherActivity.class));//Video not displayed when return from this activity by pressing back button
}
});
holder = surface.getHolder();
holder.addCallback(this);
holder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
try
{
String songName = Environment.getExternalStorageDirectory().toString()+File.separator+"1.mp4";
player.setDataSource(songName);
player.prepare();
player.start();
}
catch (Exception e)
{
e.printStackTrace();
}
}
#Override
public void surfaceChanged(SurfaceHolder holder, int format, int width, int height)
{
player.setDisplay(holder);
}
#Override
public void surfaceCreated(SurfaceHolder holder)
{
Log.d(TAG, "surfaceCreated() is called ************ holder.getSurface() = "+holder.getSurface());
}
#Override
public void surfaceDestroyed(SurfaceHolder holder)
{
Log.d(TAG, "surfaceDestroyed() is called ************");
}
I have initialized media player again and now its working fine

Categories

Resources