4

Actually i made one application for iphone and android device.. and in that video feature is available so video uploaded by iphone device,video (mp4) is cant played in android device so please any body help 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();
        }
    });

full Logcat 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
Vaishali Sutariya
  • 5,093
  • 30
  • 32

4 Answers4

2

There is an alternative approach for streaming video using the MediaPlayer class,like we use it in creating a music player. You can stream media, including video, to a MediaPlayer object using a surface view. For example, you could 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)
{
}

}

Hope this helps :)

Alok Nair
  • 3,994
  • 3
  • 24
  • 30
  • @Vaishali Implementing a streaming media player might help you. http://davanum.wordpress.com/2007/12/29/android-videomusic-player-sample-from-local-disk-as-well-as-remote-urls/ – Alok Nair Aug 13 '14 at 05:12
  • 1
    @Vaishali Also check this solution http://jan.newmarch.name/android/StreamingAudio.html – Alok Nair Aug 13 '14 at 05:12
  • @Vaishali Issue is with your url. It is not being played on VLC or GPlayer Android App. – Alok Nair Aug 13 '14 at 06:09
  • in VLC i try it .. but in that i can hear voice of vioce but cant able to see – Vaishali Sutariya Aug 13 '14 at 06:14
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/59246/discussion-between-alok-nair-and-vaishali). – Alok Nair Aug 13 '14 at 06:15
  • Actually i made one application for iphone and android device.. and in that video feature is available so video uploaded by iphone device is cant played in android device so please me – Vaishali Sutariya Aug 21 '14 at 04:04
  • What exactly do you want? – Alok Nair Aug 21 '14 at 04:10
  • i want to play video in android device.. which is uploaded by iphone users... will it be possible ? – Vaishali Sutariya Aug 21 '14 at 04:11
  • It depends on how the video and audio streams are compressed in the QuickTime file. If they're the standard H.264 and AAC, you should be able to just change the extension to .mp4 and play it that way. But if it's some weird compression format, it may just be impossible to play without QuickTime – Alok Nair Aug 21 '14 at 04:17
  • Then you can play them on Android. I don't see any issues. – Alok Nair Aug 21 '14 at 04:21
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/59699/discussion-between-alok-and-vaishali). – Alok Nair Aug 21 '14 at 04:22
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/59726/discussion-between-vaishali-and-alok). – Vaishali Sutariya Aug 21 '14 at 12:20
1

Issue:

It is issue about conflict of encoding-decoding between the video and the device's platform support.

Solution:

I would insist to use Vitamio library to play the videos in android. It is pretty simple to use and reliable also.

Example:

You can add it to your xml file like VideoView,

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

You can easily control the player,

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);
}

}

Reference:

VideoViewDemo

I hope it will be helpful to you.

Mehul Joisar
  • 15,348
  • 6
  • 48
  • 57
  • Thank you for reply @ Mehul Joisar .. but still it was not plyed – Vaishali Sutariya Aug 27 '14 at 05:02
  • Mehul joisar i used same code its working my case but there is problem android videoview orientation got changed – PrvN Aug 27 '14 at 17:54
  • @PrvN: you should check meta data of the video which provides orientation information about it. according to that orientation info, you should rotate and play the video. – Mehul Joisar Aug 28 '14 at 04:37
  • @Mehul Thanks for reply, im trying to play video from url ,how to find metadata of video from ulr – PrvN Aug 28 '14 at 18:39
  • @PrvN: If you want to support old versions then have a look at [FFmpegMediaMetadataRetriever](https://github.com/wseemann/FFmpegMediaMetadataRetriever) otherwise Android has introduced [METADATA_KEY_VIDEO_ROTATION](http://developer.android.com/reference/android/media/MediaMetadataRetriever.html#METADATA_KEY_VIDEO_ROTATION) from JellyBean – Mehul Joisar Aug 29 '14 at 07:07
  • @PrvN: If you have no concern about rotation degree, then you may try [this](http://stackoverflow.com/questions/19487063/detect-orientation-of-a-recorded-video-in-android) one easily for portrait and landscape – Mehul Joisar Aug 29 '14 at 07:10
1

Can't Play video in android uploded from iphone

Why mp4 does not play in 4 steps:

  1. download you vidView URL to PC with 'ffmpeg'

  2. $ffmpeg -i $downloadFileName

  3. inspect details of reported codecs

  4. compare those reported codecs to what android media supports

Note: very likely that #2 will report codecs not listed at #4

Community
  • 1
  • 1
Robert Rowntree
  • 6,230
  • 2
  • 24
  • 43
0

Although the video is .mp4, the video is compressed on iOS in a way that the native android media player cannot play/decode.

I ran into this exact problem OP had when developing for cross platform. An easy alternative is using VLC for Android, which is open source and built upon FFMPEG and utilizes SurfaceViews.

To do this, include the below in your build.grade file:

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

For example, you can then make a new activity for the Video, and in the 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);

Lots of info can be found here for troubleshooting: VLC for Android VideoLAN Forums

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

gareoke
  • 716
  • 6
  • 17
  • Hello, I am trying to use vlc in my xamarin.android project but the screen the video show in pixeled and grey screen for first 2 sec do you have any Idea I ask new question here, https://stackoverflow.com/questions/55357741/using-vlc-player-in-xamarin-android-project – AYKHO Mar 26 '19 at 13:47