nguyen ba thanh

+ Follow
since Apr 12, 2013
Merit badge: grant badges
For More
Cows and Likes
Total received
In last 30 days
Total given
Total received
Received in last 30 days
Total given
Given in last 30 days
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by nguyen ba thanh

This tutorial will help you how to create a simple Audio Player application.Normally,when you make a player application based on Activity, it will stop when you exit the application. So, now you will know about a technique using Service to perform playing sound. You can play music when your application is closed.

1. MediaPlayer class

MediaPlayer class can be used to control playback of audio/video files and streams. And here is some method is used to control a mediaplayer object.

mp.reset():Resets the MediaPlayer to its uninitialized state.
setDataSource(String path): Sets the data source (file-path or http/rtsp URL) to use.
mp.prepare():Prepares the player for playback, synchronously. After setting the datasource and the display surface, you need to either call prepare() or prepareAsync(). For files, it is OK to call prepare(), which blocks until MediaPlayer is ready for playback.
mp.start():Starts or resumes playback. If playback had previously been paused, playback will continue from where it was paused. If playback had been stopped, or never started before, playback will start at the beginning.
mp.getDuration():Gets the duration of the file(Return the duration in milliseconds)
mp.isPlaying():Checks whether the MediaPlayer is playing.
mp.stop():Stops playback after playback has been stopped or paused.
mp.release():Releases resources associated with this MediaPlayer object.

2. Service class

Service class: A Service is an application component representing either an application’s desire to perform a longer-running operation while not interacting with the user or to supply functionality for other applications to use. Each service class must have a corresponding declaration in its package’s AndroidManifest.xml. Services can be started with Context.startService() and Context.bindService().

3. SongProvider class

Download Sample Source code
11 years ago
This is a tutorial about customizing listview with an image and text. In this tutorial i explained how to load images from remote url and update into listview. Also explained how to design listview with your custom styles and colors instead of using default listview style.

1. Create new project in your Eclipse IDE and fill all the details. File ⇒ New Project

2. Define gradient style

Create 3 files xml named:
- gradient_bg.xml
- list_selector.xml
- gradient_bg_hover.xml
- image_bg.xml
2.1. gradient_bg.xml – Default Background Gradient Style

2.2. gradient_bg_hover.xml – Gradient Style for on hover state

2.3. list_selector.xml – Actual liststyle which combines the above two styles

2.4. image_bg.xml – is for white border around the image in listview

3. Define a listview: open your main.xml file

4. Design single list row:
Create a new XML file under layout folder and name it as list_row.xml for Single ListRow Layout. Right Click ⇒ New ⇒ Android XML File

The above XML will provide you output like below

Download sample source:

See more sample source code tutorial:

I think it will be helpfull for beginner.
11 years ago