1 # Android tutorial 5: A Complete media player
7 This tutorial wants to be the “demo application” that showcases what can
8 be done with GStreamer in the Android platform.
10 It is intended to be downloaded in final, compiled, form rather than
11 analyzed for its pedagogical value, since it adds very little GStreamer
12 knowledge over what has already been shown in [](tutorials/android/media-player.md).
15 **FIXME: Do we want to provide a binary of the app?**
19 The previous tutorial already implemented a basic media player. This one
20 simply adds a few finishing touches. In particular, it adds the
21 capability to choose the media to play, and disables the screensaver
22 during media playback.
24 These are not features directly related to GStreamer, and are therefore
25 outside the scope of these tutorials. Only a few implementation pointers
28 ## Registering as a media player
30 The `AndroidManifest.xml` tells the Android system the capabilities of
31 the application. By specifying in the `intent-filter` of the activity
32 that it understands the `audio/*`, `video/*` and `image/*` MIME types,
33 the tutorial will be offered as an option whenever an application
34 requires such medias to be viewed.
36 “Unfortunately”, GStreamer knows more file formats than Android does,
37 so, for some files, Android will not provide a MIME type. For these
38 cases, a new `intent-filter` has to be provided which ignores MIME types
39 and focuses only in the filename extension. This is inconvenient because
40 the list of extensions can be large, but there does not seem to be
41 another option. In this tutorial, only a very short list of extensions
42 is provided, for simplicity.
44 Finally, GStreamer can also playback remote files, so URI schemes like
45 `http` are supported in another `intent-filter`. Android does not
46 provide MIME types for remote files, so the filename extension list has
49 Once we have informed the system of our capabilities, it will start
51 [Intents](http://developer.android.com/reference/android/content/Intent.html)
52 to invoke our activity, which will contain the desired URI to play. In
53 the `onCreate()` method the intent that invoked the activity is
54 retrieved and checked for such URI.
56 ## Implementing a file chooser dialog
58 The UI includes a new button ![media-next) which
59 was not present in [](tutorials/android/media-player.md). It
60 invokes a file chooser dialog (based on the [Android File
61 Dialog](http://code.google.com/p/android-file-dialog/) project) that
62 allows you to choose a local media file, no matter what extension or
65 If a new media is selected, it is passed onto the native code (which
66 will set the pipeline to READY, pass the URI onto `playbin`, and bring
67 the pipeline back to the previous state). The current position is also
68 reset, so the new clip does not start in the previous position.
70 ## Preventing the screen from turning off
72 While watching a movie, there is typically no user activity. After a
73 short period of such inactivity, Android will dim the screen, and then
74 turn it off completely. To prevent this, a [Wake
75 Lock](http://developer.android.com/reference/android/os/PowerManager.WakeLock.html)
76 is used. The application acquires the lock when the Play button is
77 pressed, so the screen is never turned off, and releases it when the
78 Pause button is pressed.
82 This finishes the series of Android tutorials. Each one of the
83 preceding tutorials has evolved on top of the previous one, showing
84 how to implement a particular set of features, and concluding in this
85 tutorial 5. The goal of tutorial 5 is to build a complete media player
86 which can already be used to showcase the integration of GStreamer and
89 It has been a pleasure having you here, and see you soon!
91 [screenshot]: images/tutorials/android-a-complete-media-player-screenshot.png
92 [media-next]: images/media-next.png