The Video file format in xml

Tags: android video
Question!

I am having a problem adding a video file to my project. When I copy the file to raw files, the icon type shows like it is an xml file instead of a question mark, and when I try to call the file I can't because the file type changed from media file to xml file.

I tried to use many video files but the problem persists.

Screenshot of problem



Answers

If I am able to get your question right, you are not able to play a video file. There are several ways one can play a video in android and the easiest would be to place a video file (.mp4 extension recommended) in a raw folder (create one if you don't have it) inside of your res folder. And please get a video from here.

Place the video in your raw folder as mentioned above.

You can play the video by placing a VideoView in your xml.

CODE:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 
   android:id="@+id/LinearLayout01"
   android:layout_height="fill_parent"     
   android:paddingLeft="2px"
   android:paddingRight="2px"
   xmlns:android="http://schemas.android.com/apk/res/android"
   android:paddingTop="2px"
   android:paddingBottom="2px"
   android:layout_width="fill_parent"
   android:orientation="vertical">

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

</LinearLayout>

JAVA CODE:

 VideoView view = (VideoView)findViewById(R.id.videoView);
 String path = "android.resource://" + getPackageName() + "/" + R.raw.video_file;
 view.setVideoURI(Uri.parse(path));
 view.start();

where video_file in R.raw.video_file is your video file name. If your video file name is boom.mp4 then you can write R.raw.boom.

By : San


C standard (i.e. C11, n1570), 6.5p7:

An object shall have its stored value accessed only by an lvalue expression that has one of the following types:

  • ...
  • an aggregate or union type that includes one of the aforementioned types among its members (including, recursively, a member of a subaggregate or contained union), or a character type.

The lvalue expressions of your pointers are not union types, thus this exception does not apply. The compiler is correct exploiting this undefined behaviour.

Make the pointers' types pointers to the union type and dereference with the respective member. That should work:

union {
    ...
} u, *i, *p;
By : Olaf


Looks like this is a result of the optimizing doing its magic.

With -O0, both lines print 100 as expected (assuming little-endian). With -O2, there is some reordering going on.

gdb gives the following output:

(gdb) start
Temporary breakpoint 1 at 0x4004a0: file /tmp/x1.c, line 14.
Starting program: /tmp/x1
warning: no loadable sections found in added symbol-file system-supplied DSO at 0x2aaaaaaab000

Temporary breakpoint 1, main () at /tmp/x1.c:14
14      {
(gdb) step
15          *i  = 2;
(gdb)
18          printf(" *i = %d\n",  *i); // prints 2
(gdb)
15          *i  = 2;
(gdb)
16          *s  = 100;
(gdb)
18          printf(" *i = %d\n",  *i); // prints 2
(gdb)
 *i = 2
19          printf("u.i = %d\n", u.i); // prints 100
(gdb)
u.i = 100
22      }
(gdb)
0x0000003fa441d9f4 in __libc_start_main () from /lib64/libc.so.6
(gdb)

The reason this happens, as others have stated, is because it is undefined behavior to access a variable of one type through a pointer to another type even if the variable in question is part of a union. So the optimizer is free to do as it wishes in this case.

The variable of the other type can only be read directly via a union which guarantees well defined behavior.

What's curious is that even with -Wstrict-aliasing=2, gcc (as of 4.8.4) doesn't complain about this code.

By : dbush


This video can help you solving your question :)
By: admin