Cant Play Video (.mp4) boots from iPhone to Android

In fact, I made one application for the iphone and Android device .. and in this video the function is available, so the video downloaded using the iphone device, video (mp4) cannot be played on the Android device, so please, any body will help to me

pDialog = new ProgressDialog(this);

    // Set progressbar message
    pDialog.setMessage("Buffering...");
    pDialog.setIndeterminate(false);
    pDialog.setCancelable(false);
    // Show progressbar
    pDialog.show();

    try {
        // Start the MediaController
        MediaController mediacontroller = new MediaController(
                PlayVideoViewFromURLActivity.this);
        mediacontroller.setAnchorView(mVideoView);

        // Get the URL from String VideoURL

        Uri videoUri = Uri.parse(vidUrl); // vidUrl is url of video which on server 

        mVideoView.setMediaController(mediacontroller);
        mVideoView.setVideoURI(videoUri);

    } catch (Exception e) {

        e.printStackTrace();
    }

    mVideoView.requestFocus();
    mVideoView.setOnPreparedListener(new OnPreparedListener() {
        // Close the progress bar and play the video
        public void onPrepared(MediaPlayer mp) {
            pDialog.dismiss();
            mVideoView.start();
        }
    });
    mVideoView.setOnCompletionListener(new OnCompletionListener() {

        public void onCompletion(MediaPlayer mp) {
            if (pDialog.isShowing()) {
                pDialog.dismiss();
            }
            finish();
        }
    });

Logcat full error:

08-13 09:45:10.062: D/MediaPlayer(1929): Couldn't open file on client side, trying server side

08-13 09:45:11.770: E/MediaPlayer(1929): error (1, -2147483648)

08-13 09:45:11.790: E/MediaPlayer(1929): Error (1,-2147483648)

08-13 09:45:11.790: D/VideoView(1929): Error: 1,-2147483648
+4
source share
4 answers

There is an alternative approach for streaming video using the MediaPlayer class, for example, we use it when creating a music player. You can transfer media, including video, to a MediaPlayer object using a surface view. For example, you can use the following layout:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#000000"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" >

<SurfaceView
    android:id="@+id/surfView"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" />

MainActivity.java

public class TestAct extends Activity implements SurfaceHolder.Callback, OnPreparedListener
{

private MediaPlayer mediaPlayer;
private SurfaceHolder vidHolder;
private SurfaceView vidSurface;
String vidAddress = "https://archive.org/download/ksnn_compilation_master_the_internet/ksnn_compilation_master_the_internet_512kb.mp4";

@Override
protected void onCreate(Bundle savedInstanceState)
{
    super.onCreate(savedInstanceState);
    setContentView(R.layout.test);

    vidSurface = (SurfaceView) findViewById(R.id.surfView);
    vidHolder = vidSurface.getHolder();
    vidHolder.addCallback(this);
}

@Override
public void surfaceCreated(SurfaceHolder arg0)
{
    try
    {
        mediaPlayer = new MediaPlayer();
        mediaPlayer.setDisplay(vidHolder);
        mediaPlayer.setDataSource(vidAddress);
        mediaPlayer.prepare();
        mediaPlayer.setOnPreparedListener(this);
        mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
    }
    catch (Exception e)
    {
        e.printStackTrace();
    }
}

@Override
public void onPrepared(MediaPlayer mp)
{
    mediaPlayer.start();
}

@Override
public void surfaceDestroyed(SurfaceHolder holder)
{
}

@Override
public void surfaceChanged(SurfaceHolder arg0, int arg1, int arg2, int arg3)
{
}

}

, :)

+2

:

- .

:

Vitamio android. .

:

XML , VideoView,

   <io.vov.vitamio.widget.VideoView
    android:id="@+id/surface_view"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" />

,

public class VideoViewDemo extends Activity {

/**
 * TODO: Set the path variable to a streaming video URL or a local media file
 * path.
 */
private String path = "";
private VideoView mVideoView;
private EditText mEditText;

@Override
public void onCreate(Bundle icicle) {
    super.onCreate(icicle);
    if (!LibsChecker.checkVitamioLibs(this))
        return;
    setContentView(R.layout.videoview);
    mEditText = (EditText) findViewById(R.id.url);
    mVideoView = (VideoView) findViewById(R.id.surface_view);
    if (path == "") {
        // Tell the user to provide a media file URL/path.
        Toast.makeText(VideoViewDemo.this, "Please edit VideoViewDemo Activity, and set path" + " variable to your media file URL/path", Toast.LENGTH_LONG).show();
        return;
    } else {
        /*
         * Alternatively,for streaming media you can use
         * mVideoView.setVideoURI(Uri.parse(URLstring));
         */
        mVideoView.setVideoPath(path);
        mVideoView.setMediaController(new MediaController(this));
        mVideoView.requestFocus();

        mVideoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
            @Override
            public void onPrepared(MediaPlayer mediaPlayer) {
                // optional need Vitamio 4.0
                mediaPlayer.setPlaybackSpeed(1.0f);
            }
        });
    }

}

public void startPlay(View view) {
    String url = mEditText.getText().toString();
    path = url;
    if (!TextUtils.isEmpty(url)) {
        mVideoView.setVideoPath(url);
    }
}

public void openVideo(View View) {
  mVideoView.setVideoPath(path);
}

}

:

VideoViewDemo

, .

+1

, iphone

mp4 4 :

  • URL- vidView ffmpeg

  • $ffmpeg -i $downloadFileName

  • , android-

: , # 2 , # 4

+1

, .mp4, iOS , /.

, -. VLC Android, FFMPEG SurfaceViews.

, build.grade:

compile "de.mrmaffen:vlc-android-sdk:1.0.3"

For example, you can do a new action for video and in onCreate, do the following:

mSurfaceView = (SurfaceView) findViewById(R.id.player_surface);
mSurfaceHolder = mSurfaceView.getHolder();

mSurfaceFrame = (FrameLayout) findViewById(R.id.player_surface_frame);
mMediaUrl = getIntent().getExtras().getString("videoUrl");

try {
    mLibVLC = LibVLC.getInstance();
    mLibVLC.setAout(mLibVLC.AOUT_AUDIOTRACK);
    mLibVLC.setVout(mLibVLC.VOUT_ANDROID_SURFACE);
    mLibVLC.setHardwareAcceleration(LibVLC.HW_ACCELERATION_FULL);
    mLibVLC.eventVideoPlayerActivityCreated(Boolean.TRUE);

    mLibVLC.init(getApplicationContext());
} catch (LibVlcException e){
    Log.e(TAG, e.toString());
}

mSurfaceHolder.addCallback(mSurfaceCallback);
mSurface = mSurfaceHolder.getSurface();

mLibVLC.attachSurface(mSurface, VideoVLCActivity.this);
mLibVLC.playMRL(mMediaUrl);

You can find a lot of troubleshooting information here: VLC for Android VideoLAN Forums

Below is a more detailed example here , although it uses a different version of libvlc.LibVLC and contains different methods, it will give you a good idea about what steps are needed to add controls, set the correct size, aspect ratio, orientation, etc.

0
source

All Articles