Difference between revisions of "Kodi"

From ArchWiki
Jump to: navigation, search
(Troubleshooting: out of date hack)
(+Autostarting XBMC with login session)
(5 intermediate revisions by 3 users not shown)
Line 29: Line 29:
  
 
To use XBMC on HTPC you may want to start XBMC automatically on boot. There are a different ways to accomplish this.
 
To use XBMC on HTPC you may want to start XBMC automatically on boot. There are a different ways to accomplish this.
 +
 +
{{Note|xbmc 11.0-11 includes the xbmc group, user, and service file, so those steps can be skipped if you are using that version.}}
  
 
====Setting up a service user for XBMC====
 
====Setting up a service user for XBMC====
Line 45: Line 47:
  
 
{{Note|These instructions assume your system uses systemd as init System. Make sure to consult [[systemd]].}}
 
{{Note|These instructions assume your system uses systemd as init System. Make sure to consult [[systemd]].}}
 +
 +
{{Warning|Starting through systemd is not recommended, as XMBC will run without an login session. See below for a better approach.}}
  
 
If your system is setup for [[systemd]] you can also start XBMC outside any session using xinit. To install xinit:
 
If your system is setup for [[systemd]] you can also start XBMC outside any session using xinit. To install xinit:
Line 70: Line 74:
  
 
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]].
 
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]].
 +
 +
====Autostarting XBMC with login session====
 +
With [[ConsoleKit]] [https://www.archlinux.org/news/consolekit-replaced-by-logind/ replaced by logind] since November 2012, the solution above will not give you the power functions within XBMC anymore. So you won't be able to shut the system down from the XBMC interface.
 +
 +
The [https://bbs.archlinux.org/viewtopic.php?id=152113 recommended] way to start XBMC is to let [[systemd]] spawn a [[getty]] with autologin enabled for the xbmc user. This is described in [[Automatic_login_to_virtual_console]].
 +
 +
Getty starts the shell which has to be configured to run {{ic|startx}}. This is simply done by creating a {{ic|.bash_profile}} or {{ic|.zprofile}} file. Read [[Start_X_at_Login]] for the details.
 +
 +
XBMC is finally started from the {{ic|.xinitrc}} of the xbmc user:
 +
 +
{{hc|~/xbmc/.xinitrc|2=
 +
exec /usr/bin/xbmc-standalone
 +
}}
 +
 +
This is the output of {{ic|pstree}} when XBMC is running:
 +
 +
{{bc|
 +
systemd─┬─dbus-daemon
 +
        ├─dhcpcd
 +
        ├─login───startx───xinit─┬─X
 +
        │                        └─xbmc-standalone───xbmc───xbmc.bin───16*[{xbmc.bin}]
 +
        …
 +
}}
 +
 +
Note that XBMC won't show all the power options as long as there are other users logged in.
  
 
===Using a Remote===
 
===Using a Remote===
Line 91: Line 120:
  
 
* 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.
 
* 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.
 +
 +
==== MCE Remote with Lirc and Systemd ====
 +
 +
Install lirc-utils and link the mce config:
 +
 +
{{bc|pacman -S lirc-utils
 +
ln -s /usr/share/lirc/remotes/mceusb/lircd.conf.mceusb /etc/lirc/lircd.conf}}
 +
 +
Then, make sure the remote is using the lirc protocol.
 +
 +
{{bc|cat /sys/class/rc/rc0/protocols # [lirc] should be selected
 +
echo lirc > /sys/class/rc/rc0/protocols # manually set lirc}}
 +
 +
A udev rule can be added to make lirc the default. A write rule doesn't seem to work, so a simple RUN command can be executed instead.
 +
 +
{{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'"}}
 +
 +
Next, specify the lirc device. This varies with kernel version. As of 3.6.1 {{ic|/dev/lirc0}} should work with the default driver.
 +
 +
{{hc|/etc/conf.d/lircd.conf|2=
 +
#
 +
# 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.
 +
 +
{{hc|/etc/systemd/system/lirc.service|2=
 +
[Unit]
 +
Description=Linux Infrared Remote Control
 +
 +
[Service]
 +
EnvironmentFile=/etc/conf.d/lircd.conf
 +
ExecStartPre=/usr/bin/ln -sf /run/lirc/lircd /dev/lircd
 +
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.
 +
 +
{{bc|systemctl enable lirc
 +
systemctl start lirc}}
 +
 +
This should give a fully working mce remote.
  
 
===Fullscreen mode stretches XBMC accross multiple displays===
 
===Fullscreen mode stretches XBMC accross multiple displays===
Line 97: Line 178:
  
 
{{bc|1=SDL_VIDEO_FULLSCREEN_HEAD=0}}
 
{{bc|1=SDL_VIDEO_FULLSCREEN_HEAD=0}}
 +
 +
===Slowing down CD/DVD drive speed===
 +
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.
 +
 +
This udev-rule reduces the speed permanently:
 +
 +
{{hc|/etc/udev/rules.d/dvd-speed.rules|2=
 +
KERNEL=="sr0", ACTION=="change", ENV{DISK_MEDIA_CHANGE}=="1", RUN+="/usr/bin/eject -x 2 /dev/sr0"
 +
}}
 +
 +
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.
 +
 +
After creating the file, reload the udev rules with
 +
{{bc|udevadm control --reload}}
  
 
==Resources==
 
==Resources==
  
 
* [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]: An excellent resource with much information about Arch Linux specifically (upon which the original version of this article was largely based).

Revision as of 22:47, 11 December 2012

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.

Installation

Note: These instructions assume you have a working X installation. If you have not done this yet, please consult Beginners_Guide#Graphical_User_Interface.

The stable version of XBMC is available in the community repo:

# pacman -Syu xbmc
Note: You may want to install D-Bus and upower to enable Shutdown-Suspend-Hibernate out of XBMC.

The SVN (testing) version of XBMC can be downloaded from the AUR (XBMC-git), e.g. using yaourt:

# yaourt -Syua xbmc-git
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.

Configuration

Autostarting at Boot

To use XBMC on HTPC you may want to start XBMC automatically on boot. There are a different ways to accomplish this.

Note: xbmc 11.0-11 includes the xbmc group, user, and service file, so those steps can be skipped if you are using that version.

Setting up a service user for XBMC

To add a new user named xbmc and set a login password for it:

# useradd -m -U -G audio,video,storage,optical,power -s /bin/bash xbmc
# 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.

# 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.

Starting XBMC through systemd

Note: These instructions assume your system uses systemd as init System. Make sure to consult systemd.
Warning: Starting through systemd is not recommended, as XMBC will run without an login session. See below for a better approach.

If your system is setup for systemd you can also start XBMC outside any session using xinit. To install xinit:

# pacman -S xorg-xinit

Now you have to create a new service file.

/etc/systemd/system/xbmc.service
[Unit]
Description = Starts instance of XBMC using xinit
After = remote-fs.target

[Service]
User = xbmc
Type = simple
ExecStart = /usr/bin/xinit /usr/bin/xbmc-standalone -- :0

[Install]
WantedBy = multi-user.target

To activate this service at boot:

# systemctl enable xbmc.service

If you want to use the power functions through XBMC make sure to set up a polkit rule like described here.

Autostarting XBMC with login session

With ConsoleKit replaced by logind since November 2012, the solution above will not give you the power functions within XBMC anymore. So you won't be able to shut the system down from the XBMC interface.

The recommended way to start XBMC is to let systemd spawn a getty with autologin enabled for the xbmc user. This is described in Automatic_login_to_virtual_console.

Getty starts the shell which has to be configured to run startx. This is simply done by creating a .bash_profile or .zprofile file. Read Start_X_at_Login for the details.

XBMC is finally started from the .xinitrc of the xbmc user:

~/xbmc/.xinitrc
exec /usr/bin/xbmc-standalone

This is the output of pstree when XBMC is running:

systemd─┬─dbus-daemon
        ├─dhcpcd
        ├─login───startx───xinit─┬─X
        │                        └─xbmc-standalone───xbmc───xbmc.bin───16*[{xbmc.bin}]
        …

Note that XBMC won't show all the power options as long as there are other users logged in.

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 $ irw), add lircd to your 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 XML file at ~/.xbmc/userdata/Lircmap.xml (note the capital 'L'). Lircmap.xml format is as follows:

<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 $ 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 you automatically generated your lircd.conf using # 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 Lircmap.xml page over at the XBMC Wiki for more help and information on this subject.

MCE Remote with Lirc and Systemd

Install lirc-utils and link the mce config:

pacman -S lirc-utils
ln -s /usr/share/lirc/remotes/mceusb/lircd.conf.mceusb /etc/lirc/lircd.conf

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

cat /sys/class/rc/rc0/protocols # [lirc] should be selected
echo lirc > /sys/class/rc/rc0/protocols # manually set lirc

A udev rule can be added to make lirc the default. A write rule doesn't 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'"

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
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 accross multiple displays

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:

SDL_VIDEO_FULLSCREEN_HEAD=0

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

Resources

  • XBMC Wiki: An excellent resource with much information about Arch Linux specifically (upon which the original version of this article was largely based).