Difference between revisions of "Kodi"

From ArchWiki
Jump to: navigation, search
(Reorder and added systemd Autostart via xinit)
(removed since 12.2-7 does this now)
(44 intermediate revisions by 24 users not shown)
Line 1: Line 1:
 
[[Category:Player]]
 
[[Category:Player]]
 
 
XBMC (formerly "Xbox Media Center") is a free, [http://www.gnu.org/copyleft/gpl.html open source (GPL)] multimedia player that originally ran on the first-generation [[Wikipedia:Microsoft Xbox|XBox]], (not the newer Xbox 360), and now runs on computers running Linux, Mac OS X, Windows, and iOS. XBMC can be used to play/view the most popular video, audio, and picture formats, and many more lesser-known formats, including:  
 
XBMC (formerly "Xbox Media Center") is a free, [http://www.gnu.org/copyleft/gpl.html open source (GPL)] multimedia player that originally ran on the first-generation [[Wikipedia:Microsoft Xbox|XBox]], (not the newer Xbox 360), and now runs on computers running Linux, Mac OS X, Windows, and iOS. XBMC can be used to play/view the most popular video, audio, and picture formats, and many more lesser-known formats, including:  
  
Line 9: Line 8:
 
These can all be played directly from a CD/DVD, or from the hard-drive. XBMC can also play multimedia from a computer over a local network (LAN), or play media streams directly from the Internet. For more information, see the [http://wiki.xbmc.org/index.php?title=XBMC_FAQ XBMC FAQ].
 
These can all be played directly from a CD/DVD, or from the hard-drive. XBMC can also play multimedia from a computer over a local network (LAN), or play media streams directly from the Internet. For more information, see the [http://wiki.xbmc.org/index.php?title=XBMC_FAQ XBMC FAQ].
  
==Installation==
+
As of version 12, it can also be used to play and record live TV using a tuner, a backend server and a PVR plugin; more information about this can be found on the [http://wiki.xbmc.org/?title=PVR XBMC wiki].
  
{{Note|These instructions assume you have a working X installation. If you have not done this yet, please consult [[Beginners_Guide#Graphical_User_Interface]].}}
+
== Installation ==
 +
[[pacman|Install]] {{Pkg|xbmc}} from the [[official repositories]].
 +
Optionally install {{Pkg|xbmc-pvr-addons}} if users wish to use the pvr extensions of xbmc.
  
The stable version of XBMC is available in the community repo:
+
== Configuration ==
  
{{bc|# pacman -Syu xbmc}}
+
=== Autostarting at boot ===
 +
It is desirable to start XBMC automatically on boot.  Since version 11.0-11, the '''xbmc''' package will automatically create the xbmc group, user, and provide an xbmc.service so systemd can manage xbmc without the need for a DE.
  
 +
To make XBMC start at system boot, enable the service:
  
{{Note| You may want to install [[DBus]] and [[upower]] to enable Shutdown-Suspend-Hibernate out of XBMC.}}
+
# systemctl enable xbmc
  
 +
=== Sharing a Database Between Multiple XBMC PCs ===
 +
Provided that a box on the network is running mariadb, one can easily configure multiple xbmc boxes to share a database.  The advantage of this is that key meta are stored in one place, a show can be paused on one box and then resumed on another seamlessly, and the record of what has been watched is unified.
  
The SVN (testing) version of XBMC can be downloaded from the [[AUR]] ([https://aur.archlinux.org/packages.php?ID=45036 XBMC-git]), e.g. using yaourt:
+
Setup of this is beyond the scope of this article.  Consult [http://wiki.xbmc.org/index.php?title=HOW-TO:Share_libraries_using_MySQL/Setting_up_MySQL#tab=Arch_Linux the Setting up MySQL for Arch Linux] hosted by the XBMC project wiki.
  
{{bc|$ yaourt -Syua xbmc-git}}
+
=== Using a remote controller ===
  
{{Warning|This is not the recommended way of using XBMC, as svn versions are always on the bleeding edge of development and thus can break sometimes. If you want a stable media center experience, go with the stable releases.}}
+
As XBMC is geared toward being a remote-controlled media center; any PC with a supported IR receiver/remote, can use remote using [[LIRC]] or using the native kernel supported modules.  To work properly with xbmc, a file will be required that maps the lirc events to xbmc keypresses. Create an [[Wikipedia:XML|XML]] file at {{ic|~/.xbmc/userdata/Lircmap.xml}} (note the capital 'L').
  
===Autostarting at Boot===
+
{{Note|Users running xbmc from the included service file will find the xbmc home (~) under {{ic|/var/lib/xbmc}} and should substitute this in for the shortcut above.  Also make sure that if creating this file as the root user, it gets proper ownership as xbmc:xbmc when finished.}}
 +
Lircmap.xml format is as follows:
  
To use XBMC on a HTPC you may want to start XBMC automatically on boot. There are a different ways to accomplish this.
+
{{bc|1=<lircmap>
 +
  <remote device="devicename">
 +
      <XBMC_button>LIRC_button</XBMC_button>
 +
      ...
 +
  </remote>
 +
</lircmap>}}
  
====Setting up a service user for XBMC====
+
* '''Device Name''' is whatever LIRC calls the remote. This is set using the '''Name''' directive in lircd.conf and can be viewed by running {{ic|$ irw}} and pressing a few buttons on the remote. IRW will report the name of the button pressed and the name of the remote will appear on the end of the line.
  
To add a new user named ''xbmc'' and set a login password for it:
+
* '''XBMC_button''' is the name of the button as defined in [http://wiki.xbmc.org/index.php?title=Keymap.xml keymap.xml].
  
{{bc|1= $ useradd -m -U -G audio,video,storage,optical,power -s /bin/bash ''xbmc''
+
* '''LIRC_button''' is the name as defined in {{ic|lircd.conf}}. If lircd.conf was autogenerated using {{ic|# irrecord}}, these are the names selected for the buttons. Refer back to [[LIRC]] for more information.
$ passwd ''xbmc''}}
+
  
To use an existing user make sure you add your user (or whatever user will run xmbc on your system) to at least groups audio, video, and storage.  
+
* A very thorough [http://wiki.xbmc.org/index.php?title=Lircmap.xml Lircmap.xml] page over at the [http://wiki.xbmc.org/index.php?title=Main_Page XBMC Wiki] should be consulted for more help and information on this subject as this is out of scope of this article.
{{bc|for x in audio video storage; do sudo gpasswd -a $USER $x; done}}
+
  
{{Note|If you do not run [[Sudo]], simply run the above command as root. You may also need to swap out $USER for another username if you are not logged in as the xbmc user.}}
+
==== MCE remote with Lirc and Systemd ====
  
 +
Install {{Pkg|lirc-utils}} and link the mce config:
  
====Starting XBMC through initscripts====
+
# ln -s /usr/share/lirc/mceusb/lircd.conf.mceusb /etc/lirc/lircd.conf
  
First install [[D-Bus]] and add it to your [[Daemons#Starting_on_Boot|DAEMONS Array]] if you have not already:
+
Then, make sure the remote is using the lirc protocol:
 +
$ cat /sys/class/rc/rc0/protocols
 +
If not, issue:
 +
# echo lirc > /sys/class/rc/rc0/protocols
  
{{bc|(... '''dbus''' ...)}}
+
A udev rule can be added to make lirc the default. A write rule does not seem to work, so a simple RUN command can be executed instead.
  
Next, you'll probably want to get [[ConsoleKit]] up and running, if you have not already, and add the following line to your {{ic|.xinitrc}}:
+
{{hc|/etc/udev/rules.d/99-lirc.rules|2=
 +
KERNEL=="rc*", SUBSYSTEM=="rc", ATTR{protocols}=="*lirc*", RUN+="/bin/sh -c 'echo lirc > $sys$devpath/protocols'"}}
  
{{bc|exec ck-launch-session xbmc-standalone}}
+
{{Note|If this does not work, follow the suggestion to use tmpfiles.d as specified in the [[LIRC#Kernel_module_change|LIRC wiki]] to set the remote to the lirc protocol at boot time.}}
  
 +
Next, specify the lirc device. This varies with kernel version. As of 3.6.1 {{ic|/dev/lirc0}} should work with the default driver.
  
Using the above method, xbmc should run every time you start your X server, so auto-starting at boot can be configured just like a [[Display Manager]], with one important difference. If you choose to use the {{ic|/etc/inittab}} method, you can skip loading a display manager altogether and autologin XBMC by default. To do this, change your default runlevel to 5 in {{ic|/etc/inittab}} as usual:
+
{{hc|/etc/conf.d/lircd.conf|2=
 +
#
 +
# Parameters for lirc daemon
 +
#
  
{{bc|## Only one of the following two lines can be uncommented!
+
LIRC_DEVICE="/dev/lirc0"
# Boot to console
+
LIRC_DRIVER="default"
'''#'''id:3:initdefault:
+
LIRC_EXTRAOPTS=""
# Boot to X11
+
LIRC_CONFIGFILE=""}}
id:5:initdefault:}}
+
  
Note the comment (#) in front of {{ic|id:3:initdefault:}} and not {{ic|id:5:initdefault}}. Then, comment out all the default display manager lines at the end of the file:
+
The default service file for lirc ignores this conf file. So we need to create a custom one.
  
{{bc|# Example lines for starting a login manager
+
{{hc|/etc/systemd/system/lirc.service|2=
#x:5:respawn:/usr/bin/xdm -nodaemon
+
#x:5:respawn:/usr/sbin/gdm -nodaemon
+
#x:5:respawn:/usr/bin/kdm -nodaemon
+
#x:5:respawn:/usr/bin/slim >/dev/null 2>&1}}
+
 
+
Finally, add this line (toward the end of the file, near where the lines you just commented are):
+
 
+
{{bc|x:5:wait:login -f <YOUR_XBMC_USERNAME> </dev/tty7 &>/dev/tty7}}
+
 
+
{{Warning|'''There is a security risk using this method.''' This bypasses login authentication and should only be used if you are sure you know what you are doing!}}
+
 
+
If you use systemd you can try this:
+
{{hc|/etc/systemd/system/autologin.service|<nowiki>
+
 
[Unit]
 
[Unit]
Description=Direct login to X
+
Description=Linux Infrared Remote Control
After=systemd-user-sessions.service
+
  
 
[Service]
 
[Service]
Restart=always
+
EnvironmentFile=/etc/conf.d/lircd.conf
ExecStart=/sbin/mingetty --autologin <username> tty7 linux
+
ExecStartPre=/usr/bin/ln -sf /run/lirc/lircd /dev/lircd
 +
ExecStartPre=/usr/bin/ln -sf /dev/lirc0 /dev/lirc
 +
ExecStart=/usr/sbin/lircd --pidfile=/run/lirc/lircd.pid --device=${LIRC_DEVICE} --driver=${LIRC_DRIVER}
 +
Type=forking
 +
PIDFile=/run/lirc/lircd.pid
  
 
[Install]
 
[Install]
WantedBy=graphical.target
+
WantedBy=multi-user.target}}
</nowiki>}}
+
 
+
Also you need install mingetty package.
+
 
+
Save your {{ic|/etc/inittab}} changes and add the following to your {{ic|.bash_profile}}:
+
 
+
{{bc|<nowiki>[[ $(tty) = "/dev/tty7" ]] && exec startx </dev/null &>/dev/null</nowiki>}}
+
 
+
You may also add a {{ic|.hushlogin}} to your home directory to further suppress login messages:
+
 
+
{{bc|touch ~/.hushlogin}}
+
 
+
====Starting XBMC through systemd====
+
 
+
{{Note|These instructions assume your system uses systemd as init System. Make sure to consult [[systemd]].}}
+
 
+
If your system is setup for [[systemd]] you can also start XBMC outside any session using xinit. To install xinit:
+
 
+
{{bc|$ pacman -S xinit}}
+
 
+
Now you have to create a new service file.
+
 
+
{{hc|/etc/systemd/system/xbmc.service|2=
+
[Unit]
+
Description = Starts instance of XBMC using xinit
+
After = remote-fs.target
+
 
+
[Service]
+
User = xbmc
+
Group = users
+
Type = simple
+
ExecStart = /usr/bin/xinit /usr/bin/xbmc-standalone -- :0
+
 
+
[Install]
+
WantedBy = multi-user.target}}
+
 
+
To activate this service at boot:
+
 
+
{{bc|$ sudo systemctl enable xbmc.service}}
+
 
+
If you want to use the power functions through XBMC make sure to set up a polkit rule like described [[Xbmc#Shutdown-Suspend-Hibernate does not work|here]].
+
 
+
==Configuration==
+
 
+
===Using a Remote===
+
 
+
As XBMC is geared toward being a remote-controlled media center, if your computer has an IR receiver, you will probably want to set up a remote using [[LIRC]]. Once you are sure your remote is working properly (tested with {{ic|$ irw}}), add '''lircd''' to your [[Daemons#Starting_on_Boot|DAEMONS Array]] and you'll be ready to create an Lircmap.xml file for it.
+
 
+
Using your favorite text editor, you'll need to go in and create an [[Wikipedia:XML|XML]] file at {{ic|~/.xbmc/userdata/Lircmap.xml}} (note the capital 'L'). Lircmap.xml format is as follows:
+
 
+
{{bc|1=<lircmap>
+
  <remote device="devicename">
+
      <XBMC_button>LIRC_button</XBMC_button>
+
      ...
+
  </remote>
+
</lircmap>}}
+
 
+
* '''Device Name''' is whatever LIRC calls your remote. This is set using the '''Name''' directive in lircd.conf and can be viewed by running {{ic|$ irw}} and pressing a few buttons on the remote. IRW will report the name of the button pressed and the name of the remote will appear on the end of the line.
+
 
+
* '''XBMC_button''' is the name of the button as defined in [http://wiki.xbmc.org/index.php?title=Keymap.xml keymap.xml].
+
 
+
* '''LIRC_button''' is the name as defined in {{ic|lircd.conf}}. If you automatically generated your lircd.conf using {{ic|# irrecord}}, these are the names you selected for your button then. Refer back to [[LIRC]] for more information.
+
 
+
* You may want to check out the very thorough [http://wiki.xbmc.org/index.php?title=Lircmap.xml Lircmap.xml] page over at the [http://wiki.xbmc.org/index.php?title=Main_Page XBMC Wiki] for more help and information on this subject.
+
  
===Fullscreen mode stretches XBMC accross multiple displays===
+
Finally, enable and start the lirc service:
  
If you have got a multi-monitor setup and don't want XBMC to stretch accross all screens, you can restrict the fullscreen mode to one display, by setting the environment variable SDL_VIDEO_FULLSCREEN_HEAD to the number of the desired target display. For example if you want XBMC to show up on display 0 you can add the following line to your [[Bashrc]]:
+
# systemctl enable lirc
 +
# systemctl start lirc
  
{{bc|1=SDL_VIDEO_FULLSCREEN_HEAD=0}}
+
This should give a fully working mce remote.
  
==Troubleshooting==
+
=== Fullscreen mode stretches XBMC across multiple displays ===
  
===Shutdown-Suspend-Hibernate does not work===
+
For a multi-monitor setup, XBMC may default to stretching across all screens.  One can restrict the fullscreen mode to one display by setting the environment variable SDL_VIDEO_FULLSCREEN_HEAD to the number of the desired target display. For example, having xbmc show up on display 0, add the following line to the xbmc user's [[Bashrc]]:
  
If you have problems with shutdown, suspend or hibernate within XBMC make sure your user is in the ''wheel'' group and also that the [[upower]] package is installed.
+
SDL_VIDEO_FULLSCREEN_HEAD=0
  
 +
{{Note|Mouse cursor will be held inside screen with XBMC.}}
  
In case XBMC was configured to be started outside any session, you need to explicitely give the appropriate rights by creating a [[polkit]] rule.
+
=== Slowing down CD/DVD drive speed ===
Create a new policy rule with the following contents (assuming xbmc as user running xbmc):
+
  
{{hc|/var/lib/polkit-1/localauthority/50-local.d/xbmc.pkla|2=
+
The {{ic|eject}} program from the {{ic|util-linux}} package does a nice job for this, but its setting is cleared as soon as the media is changed.
[Actions for '''xbmc''' user]
+
Identity=unix-user:'''xbmc'''
+
Action=org.freedesktop.upower.*;org.freedesktop.consolekit.system.*
+
ResultAny=yes
+
ResultInactive=yes
+
ResultActive=yes}}
+
  
===ConsoleKit Issues with Automatic Login via /etc/inittab===
+
This udev-rule reduces the speed permanently:
  
[[ConsoleKit]] is known to have problems registering a session as both local and active when logging in directly via the {{ic|/etc/inittab}} method described above. If you would like to be able to shutdown and reboot your machine directly from XBMC while logging in via {{ic|/etc/inittab}}, perform the autologin via mingetty (note: this method requires '''mingetty''' and '''upower''' to be installed). There are two steps involved:
+
{{hc|/etc/udev/rules.d/dvd-speed.rules|2=
* 1. Comment out the line {{ic|x:5:wait:login -f <YOUR_XBMC_USERNAME> </dev/tty7 &>/dev/tty7}} from above and, in the consoles section of {{ic|/etc/inittab}}, append the following:
+
KERNEL=="sr0", ACTION=="change", ENV{DISK_MEDIA_CHANGE}=="1", RUN+="/usr/bin/eject -x 2 /dev/sr0"
{{bc|c7:2345:wait:/sbin/mingetty --autologin <YOUR_XBMC_USERNAME> tty7 linux}}
+
}}
  
* 2. Then, in your XBMC user's {{ic|~/.bash_profile}}, include the following (in place of the {{ic|.bash_profile}} line indicated above) (source: [https://bbs.archlinux.org/viewtopic.php?pid=887022#p887022 Arch forums]):
+
Replace {{ic|sr0}} with the device name of your optical drive. Replace {{ic|-x 2}} with {{ic|-x 4}} if you prefer 4x-speed instead of 2x-speed.
{{bc|<nowiki>[[ $(tty) = "/dev/tty7" ]] && exec xinit ~/.xinitrc -- /usr/bin/X -nolisten tcp vt08 &>/dev/null</nowiki>}}
+
  
 +
After creating the file, reload the udev rules with
 +
# udevadm control --reload
  
==Resources==
+
== See also ==
  
* [http://wiki.xbmc.org/index.php?title=Main_Page XBMC Wiki]: An excellent resource with much information about Arch Linux specifically (upon which the original version of this article was largely based).
+
* [http://wiki.xbmc.org/index.php?title=Main_Page XBMC Wiki] - Excellent resource with much information about Arch Linux specifically

Revision as of 14:49, 28 November 2013

XBMC (formerly "Xbox Media Center") is a free, open source (GPL) multimedia player that originally ran on the first-generation XBox, (not the newer Xbox 360), and now runs on computers running Linux, Mac OS X, Windows, and iOS. XBMC can be used to play/view the most popular video, audio, and picture formats, and many more lesser-known formats, including:

  • Video - DVD-Video, VCD/SVCD, MPEG-1/2/4, DivX, XviD, Matroska
  • Audio - MP3, AAC.
  • Picture - JPG, GIF, PNG.

These can all be played directly from a CD/DVD, or from the hard-drive. XBMC can also play multimedia from a computer over a local network (LAN), or play media streams directly from the Internet. For more information, see the XBMC FAQ.

As of version 12, it can also be used to play and record live TV using a tuner, a backend server and a PVR plugin; more information about this can be found on the XBMC wiki.

Installation

Install xbmc from the official repositories. Optionally install xbmc-pvr-addons if users wish to use the pvr extensions of xbmc.

Configuration

Autostarting at boot

It is desirable to start XBMC automatically on boot. Since version 11.0-11, the xbmc package will automatically create the xbmc group, user, and provide an xbmc.service so systemd can manage xbmc without the need for a DE.

To make XBMC start at system boot, enable the service:

# systemctl enable xbmc

Sharing a Database Between Multiple XBMC PCs

Provided that a box on the network is running mariadb, one can easily configure multiple xbmc boxes to share a database. The advantage of this is that key meta are stored in one place, a show can be paused on one box and then resumed on another seamlessly, and the record of what has been watched is unified.

Setup of this is beyond the scope of this article. Consult the Setting up MySQL for Arch Linux hosted by the XBMC project wiki.

Using a remote controller

As XBMC is geared toward being a remote-controlled media center; any PC with a supported IR receiver/remote, can use remote using LIRC or using the native kernel supported modules. To work properly with xbmc, a file will be required that maps the lirc events to xbmc keypresses. Create an XML file at ~/.xbmc/userdata/Lircmap.xml (note the capital 'L').

Note: Users running xbmc from the included service file will find the xbmc home (~) under /var/lib/xbmc and should substitute this in for the shortcut above. Also make sure that if creating this file as the root user, it gets proper ownership as xbmc:xbmc when finished.

Lircmap.xml format is as follows:

<lircmap>
  <remote device="devicename">
      <XBMC_button>LIRC_button</XBMC_button>
      ...
  </remote>
</lircmap>
  • Device Name is whatever LIRC calls the remote. This is set using the Name directive in lircd.conf and can be viewed by running $ irw and pressing a few buttons on the remote. IRW will report the name of the button pressed and the name of the remote will appear on the end of the line.
  • XBMC_button is the name of the button as defined in keymap.xml.
  • LIRC_button is the name as defined in lircd.conf. If lircd.conf was autogenerated using # irrecord, these are the names selected for the buttons. Refer back to LIRC for more information.
  • A very thorough Lircmap.xml page over at the XBMC Wiki should be consulted for more help and information on this subject as this is out of scope of this article.

MCE remote with Lirc and Systemd

Install lirc-utils and link the mce config:

# ln -s /usr/share/lirc/mceusb/lircd.conf.mceusb /etc/lirc/lircd.conf

Then, make sure the remote is using the lirc protocol:

$ cat /sys/class/rc/rc0/protocols

If not, issue:

# echo lirc > /sys/class/rc/rc0/protocols

A udev rule can be added to make lirc the default. A write rule does not seem to work, so a simple RUN command can be executed instead.

/etc/udev/rules.d/99-lirc.rules
KERNEL=="rc*", SUBSYSTEM=="rc", ATTR{protocols}=="*lirc*", RUN+="/bin/sh -c 'echo lirc > $sys$devpath/protocols'"
Note: If this does not work, follow the suggestion to use tmpfiles.d as specified in the LIRC wiki to set the remote to the lirc protocol at boot time.

Next, specify the lirc device. This varies with kernel version. As of 3.6.1 /dev/lirc0 should work with the default driver.

/etc/conf.d/lircd.conf
#
# Parameters for lirc daemon
#

LIRC_DEVICE="/dev/lirc0"
LIRC_DRIVER="default"
LIRC_EXTRAOPTS=""
LIRC_CONFIGFILE=""

The default service file for lirc ignores this conf file. So we need to create a custom one.

/etc/systemd/system/lirc.service
[Unit]
Description=Linux Infrared Remote Control

[Service]
EnvironmentFile=/etc/conf.d/lircd.conf
ExecStartPre=/usr/bin/ln -sf /run/lirc/lircd /dev/lircd
ExecStartPre=/usr/bin/ln -sf /dev/lirc0 /dev/lirc
ExecStart=/usr/sbin/lircd --pidfile=/run/lirc/lircd.pid --device=${LIRC_DEVICE} --driver=${LIRC_DRIVER}
Type=forking
PIDFile=/run/lirc/lircd.pid

[Install]
WantedBy=multi-user.target

Finally, enable and start the lirc service:

# systemctl enable lirc
# systemctl start lirc

This should give a fully working mce remote.

Fullscreen mode stretches XBMC across multiple displays

For a multi-monitor setup, XBMC may default to stretching across all screens. One can restrict the fullscreen mode to one display by setting the environment variable SDL_VIDEO_FULLSCREEN_HEAD to the number of the desired target display. For example, having xbmc show up on display 0, add the following line to the xbmc user's Bashrc:

SDL_VIDEO_FULLSCREEN_HEAD=0
Note: Mouse cursor will be held inside screen with XBMC.

Slowing down CD/DVD drive speed

The eject program from the util-linux package does a nice job for this, but its setting is cleared as soon as the media is changed.

This udev-rule reduces the speed permanently:

/etc/udev/rules.d/dvd-speed.rules
KERNEL=="sr0", ACTION=="change", ENV{DISK_MEDIA_CHANGE}=="1", RUN+="/usr/bin/eject -x 2 /dev/sr0"

Replace sr0 with the device name of your optical drive. Replace -x 2 with -x 4 if you prefer 4x-speed instead of 2x-speed.

After creating the file, reload the udev rules with

# udevadm control --reload

See also

  • XBMC Wiki - Excellent resource with much information about Arch Linux specifically