The following commentary on the Samma Ditthi Sutta explains in detail what sexual misconduct means (in Therevada Buddhism). The fact it has to involve sex with another person excludes masturbation as a misconduct for lay people. In my understanding, this behavior presents an obstacle to samadhi and liberation, just like addiction to chocolate would, but is not a violation of the precept per say. The precepts are about the principles of harmlessness: i.e. Is anyone being harmed? If it was about avoiding hindrances to liberation, sila would be impractical or very difficult to lay Buddhists: we would have precepts like avoiding good food, sweets, shows, music, dancing, and so forth, some of these which the Buddha prohibited for monks, but not for lay followers.
The five precepts are about very coarse behaviors that create direct harm in obvious ways. Even though one could say indulging in sense pleasures is harmful in that it prolongs Samsara, as said above, if lay precepts were meant to avoid ALL sense attachment, the Buddha would have told lay people to follow monk rules, including complete celibacy. But he did not do that.
Here's the commentary I mentioned above:
Misconduct in sensual pleasures (kamesu micchacara): here, "in sensual pleasures" (kamesu) means in regard to sexual intercourse. "Misconduct" is entirely reprehensible vile conduct. As to characteristic, sexual misconduct is the volition to transgress bounds occurring through the body door by way of unrighteous intent.
Herein, out of bounds for men, firstly, are the twenty kinds of women, that is, the ten beginning with those protected by the mother, namely, "protected by the mother, protected by the father, protected by the mother and father, protected by the brother, protected by the sister, protected by relatives, protected by the clan, protected by the law, under protection, entailing a penalty"; and the ten beginning with those purchased with money, namely, "one purchased with money, one who lives (with a man) by her own desire, one who lives (with a man) on account of wealth, one who lives (with a man) on account of cloth, one who is given (in marriage with the ceremony of) dipping the hand in water, one who has been (taken to wife and) relieved of her burden-carrying head-pad, one who is a slave and a wife, one who is a servant and a wife, one who is carried off in a raid, one engaged at so much a time."
Then, as concerns women, for the twelve kinds of women consisting of the two, namely, under protection and entailing a penalty, and the ten beginning with those purchased with money, other men are out of bounds.
This sexual misconduct is less blameworthy when (the person) out of bounds is without good qualities such as virtue, etc., and more blameworthy when (the person) possesses good qualities such as virtue, etc. There are four constituents of this act: an object which is out of bounds, the mind to engage in that, the effort to engage, and consent to the union of sexual organs. The means is single: one's own person.