Video can't be played


#1

Hi, I am doing the challenge about playing the video and have some troubles with it. I’m trying to solve the Problem with VideoView.
When I try to play docu.mp4 a message appears saying “Video can’t be played”.
I hope you can help me.

09-11 21:36:47.411: E/MediaPlayer(19653): Error (1,-2147483648) <- this error appears!

HelloMoonFragment.java

public class HelloMoonFragment extends Fragment
{
	private Button mPlayButton;
	private Button mStopButton;
	private ImageView mImage;
	private VideoView mVideo;
...
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup parent, Bundle savedInstanceState) 
{
View v = inflater.inflate(R.layout.fragment_hello_moon, parent, false);

mStopButton = (Button)v.findViewById(R.id.hellomoon_stopButton);
mPlayButton = (Button)v.findViewById(R.id.hellomoon_playButton);
mImage = (ImageView)v.findViewById(R.id.image_view);
mVideo = (VideoView)v.findViewById(R.id.video_view);

mPlayButton.setOnClickListener(new View.OnClickListener() 
{

@Override
public void onClick(View v) 
{
...
Uri videoUri = Uri.parse("android.resource://" + "com.bignerdranch.android.hellomoon/raw/docu");
MediaController mp = new MediaController(getActivity());
mVideo.setMediaController(mp);
mp.setAnchorView(mVideo);

mVideo.setVideoURI(videoUri);
mVideo.requestFocus();
mVideo.start();
}
}
}
}

fragment_hello_moon.xml

<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >
    
   <ImageView 
    android:src="@drawable/moon"
    android:id="@+id/image_view"
    android:contentDescription="@string/hellomoon_description"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:scaleType="centerInside"
    android:layout_weight="1" />  

    
   <VideoView
    android:layout_height="match_parent"
    android:layout_width="match_parent"
    android:scaleType="centerInside"
    android:id="@+id/video_view"
    android:layout_weight="1" 
    android:visibility="gone"/> 
         
  <TableRow 
    android:gravity="center|bottom"
    android:layout_weight="0" >
    
  <Button android:id="@+id/hellomoon_playButton"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:text="@string/hellomoon_play" />
    
  <Button android:id="@+id/hellomoon_stopButton"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:text="@string/hellomoon_stop"/>
  
   </TableRow>
   
</TableLayout>

#2

Can you show more of your LogCat? What leads up to this error?


#3

This should be the interesting part. As you ask for more LogCat Info I recognized this first error. But I don’t know how to solve it.

09-14 15:20:31.371: E/(235): Failed to open file 'android.resource://com.bignerdranch.android.hellomoon/2130968580'. (No such file or directory)
09-14 15:20:31.371: E/AwesomePlayer(235): data source creating fail
09-14 15:20:31.371: E/MediaPlayer(16111): error (1, -2147483648)
09-14 15:20:31.391: D/MediaPlayer(16111): Mediaplayer receives message, message type: 100
09-14 15:20:31.391: E/MediaPlayer(16111): Error (1,-2147483648)
09-14 15:20:31.391: D/VideoView(16111): Error: 1,-2147483648
09-14 15:20:31.411: D/HtcDeviceInfoManager(677): MediaReceiver.onReceive
09-14 15:20:31.411: V/HtcDeviceInfoManager(677): act =2 pid =16111 type=1
09-14 15:20:31.451: D/qdmemalloc(222): ion: Allocated buffer base:0x4471d000 size:1622016 fd:97
09-14 15:20:31.451: D/qdmemalloc(222): ion: Allocated buffer base:0x400e4000 size:4096 fd:100
09-14 15:20:31.451: D/qdmemalloc(16111): ion: Mapped buffer base:0x6ea2b000 size:1622016 offset:0 fd:62
09-14 15:20:31.451: D/qdmemalloc(16111): ion: Mapped buffer base:0x6b0a1000 size:4096 offset:0 fd:63

#4

First, regarding the error code:

[quote]When looking at the error value (1, -2147483648), the ‘1’ value corresponds to the constant in MediaPlayer.MEDIA_ERROR_UNKNOWN. -2147483648 corresponds to hexadecimal 0x80000000 which is defined as UNKNOWN_ERROR in frameworks/native/include/utils/Errors.h. This shows that the error’s source is hard to pin down …
[/quote]http://stackoverflow.com/a/18084143

You define your URI using the “com.bignerdranch.android.hellomoon/raw/docu” path. Is your video file really called docu.xxx ? This might be the first step since LogCat is complaining about not finding that file.

Aside, I have tried this challenge both ways (using MediaPlayer/SurfaceView and VideoView/MediaController). I am getting an error both times. Its crapping out in MediaPlayer.onPrepare(). Not sure why though.


#5

Hi, thx for your info/help. And yes, my file has definitely the name docu.mp4. I tried others as well, but the result was the same!
To bad. I guess that seems to be buggy!


#6

Android does not provide great feedback on codec support at all. Basically, codec support will vary from device to device.

Check out the thread here for more info: http://forums.bignerdranch.com/viewtopic.php?f=410&t=6332


#7

I converted the video to. m4v format and it worked using the VideoView method


#8

Yes I found the same thing it works with an mp4 file but not an mpg file


#9

Same for me. I converted it to mp4 and now it’s working.