Month: December 2010

  • Simple Android mp3 media player example

    Simple Android mp3 media player example

    Here i want to write about my first experience in Android Dev.
    This application just play embedded in application mp3 file. That’s all.
    Below you can download the source code.
    In first step i create a simple Android UI. Below you can see this:

    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout
    android:id="@+id/widget31"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    xmlns:android="http://schemas.android.com/apk/res/android">
        <Button
            android:text="@string/play_str"
            android:textSize="15pt"
            android:textStyle="bold"
            android:id="@+id/ButtonPlayStop"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"/>
        <SeekBar
            android:id="@+id/SeekBar01"
            android:layout_height="wrap_content"
            android:layout_width="fill_parent"
            android:layout_below="@id/ButtonPlayStop"/>
    </RelativeLayout>

    In my simple mp3 media player i have few string constans, like “PLAY”, “PAUSE”, etc. The best practice is place this constats in special part of project. That part call values. In this part i Eclipse create for me strings.xml file and change it. Bellow you can see strings.xml content:

    <?xml version="1.0" encoding="utf-8"?>
    <resources>
        <string name="app_name">Android mp3 player</string>
        <string name="play_str">PLAY</string>
        <string name="pause_str">PAUSE</string>
    </resources>

    It’s very simple and useful practice.

    Next i make changes in Activity file (Mp3player.java). Bellow i give you some comments about it:

    package com.hrupin.mp3player;
    
    import com.hrupin.mp3player.R;
    
    import android.app.Activity;
    import android.media.MediaPlayer;
    import android.os.Bundle;
    import android.os.Handler;
    import android.view.MotionEvent;
    import android.view.View;
    import android.view.View.OnClickListener;
    import android.view.View.OnTouchListener;
    import android.widget.Button;
    import android.widget.SeekBar;
    
    public class Mp3player extends Activity {
    
        private Button buttonPlayStop;
        private MediaPlayer mediaPlayer;
        private SeekBar seekBar;
    
        private final Handler handler = new Handler();
    
        // Here i override onCreate method.
        //
        // setContentView() method set the layout that you will see then
        // the application will starts
        //
        // initViews() method i create to init views components.
        @Override
        public void onCreate(Bundle icicle) {
                super.onCreate(icicle);
                setContentView(R.layout.main);
                initViews();  
    
        }
    
        // This method set the setOnClickListener and method for it (buttonClick())
        private void initViews() {
            buttonPlayStop = (Button) findViewById(R.id.ButtonPlayStop);
            buttonPlayStop.setOnClickListener(new OnClickListener() {@Override public void onClick(View v) {buttonClick();}});
    
            mediaPlayer = MediaPlayer.create(this, R.raw.testsong_20_sec); 
    
            seekBar = (SeekBar) findViewById(R.id.SeekBar01);
            seekBar.setMax(mediaPlayer.getDuration());
            seekBar.setOnTouchListener(new OnTouchListener() {@Override public boolean onTouch(View v, MotionEvent event) {
            	seekChange(v);
    			return false; }
    		});
    
        }
    
        public void startPlayProgressUpdater() {
        	seekBar.setProgress(mediaPlayer.getCurrentPosition());
    
    		if (mediaPlayer.isPlaying()) {
    			Runnable notification = new Runnable() {
    		        public void run() {
    		        	startPlayProgressUpdater();
    				}
    		    };
    		    handler.postDelayed(notification,1000);
        	}else{
        		mediaPlayer.pause();
        		buttonPlayStop.setText(getString(R.string.play_str));
        		seekBar.setProgress(0);
        	}
        } 
    
        // This is event handler thumb moving event
        private void seekChange(View v){
        	if(mediaPlayer.isPlaying()){
    	    	SeekBar sb = (SeekBar)v;
    			mediaPlayer.seekTo(sb.getProgress());
    		}
        }
    
        // This is event handler for buttonClick event
        private void buttonClick(){
            if (buttonPlayStop.getText() == getString(R.string.play_str)) {
                buttonPlayStop.setText(getString(R.string.pause_str));
                try{
                	mediaPlayer.start();
                    startPlayProgressUpdater();
                }catch (IllegalStateException e) {
                	mediaPlayer.pause();
                }
            }else {
                buttonPlayStop.setText(getString(R.string.play_str));
                mediaPlayer.pause();
            }
        }
    }
    Download it from github
  • Linux Ubuntu 10.04 driver for my Canon IP3600 IJ printer

    Linux Ubuntu 10.04 driver for my Canon IP3600 IJ printer

    Let me tell you how i installed Canon Pixma IP3600 printer driver in Ubuntu 10.04 Lucid Lynx and made it works.

    Yesterday, i needed to install driver for my IJ printer. I tried to found it in Ubuntu software center, but it was unsuccess.

    Next i downloaded the driver from official web site: Debian Linux Printer Driver .In this .tar archive i was found three files:

    • cnijfilter-common_3.00-1_i386.deb – common .deb file. Needs to  … i think … to all Canon printers.
    • cnijfilter-ip3600series_3.00-1_i386.deb – driver for printer with PPD file.
    • cnijfilter-common-3.00-1.tar.gz – source

    I tried to install this .deb packages, but it was unsuccess. I’ve got an error depended with libcupsys2 library (in new release this library replaced by libcups2). I changed library libcupsys2 to  libcups2 in packages then rebuild it and install in my OS (Ubuntu 10.04) succesful. I show you how i did this.

    1. Download the archive with packages from oficial website: Debian Linux Printer Driver
    2. Untar this archive.
    3. Open terminal and execute next command according by your .deb packages dir location:
      dpkg-deb -x cnijfilter-common_3.00-1_i386.deb common
      dpkg-deb --control cnijfilter-common_3.00-1_i386.deb
    4. You will got two dirs (common, DEBIAN). Open DEBIAN/control file and replace libcupsys2 by libcups2. After changes save it.
    5. Move whole DEBIAN dir in to common dir
    6. Next you need to create .deb package from common dir:
      dpkg -b common new_cnijfilter-common_3.00-1_i386.deb
    7. Now you can install this package with no problem.
    8. Do same operations (steps 3-7) with other .deb file (cnijfilter-ip3600series_3.00-1_i386.deb)

    After installation the system tells you that printer is ready to print. But if you start print job you have got some issue:

    Status Messages
    There are status massages associated with this queue.
    The printer’s state message is: ‘Filter “/usr/lib/cups/filter/pstocanonij” for printer “iP3600-series” not owned by root’.
    igor@igor-laptop:/usr/lib/cups/filter$ ls -l
    -rwxr-xr-x 1 igor igor  21044 2008-11-05 08:06 pstocanonij

    To fix this you must change /usr/lib/cups/filter/pstocanonij file owner to root.

    sudo chown root:root /usr/lib/cups/filter/pstocanonij

    Thats all. Enjoy printing with Canon Pixma IP3600 printer on Ubuntu.

    To make this operation simple for me i write some bash script: ip3600.sh .Below you can download archive with this script. Just untar this archive to work with it.

    tar xvf ip3600.sh.tar.gz

    And run this script with sudo. Example of usage:

    ip3600_debian_printer – dir which contains cnijfilter-common_3.00-1_i386.deb ,cnijfilter-ip3600series_3.00-1_i386.deb, cnijfilter-common-3.00-1.tar.gz files

    sudo ./ip3600.sh ~/Temp/ip3600_debian_printer/

    For more information look in ip3600.sh file. I not guarantee that this script (ip3600.sh) will works in your system.

    I hope it will useful for you.

    Download it from github