I applaud your effort to ask this matter so candidly.
I have not read a Buddhist story that directly discusses the matter of masturbation but, as a Chinese Buddhist, there are many Chinese influences/wisdom, that we also study as electives, that discusses the matter of masturbation.
Chinese Buddhists often build our foundation with some aspects in Confucianism and Daoism, before diving into Mahayana. Historically many Buddhist masters are not only expert in Buddhism, but often are highly educated in Confucianist and Daoist scripture and skills.
The matter of masturbation and sexuality in general are often discussed in the context of Chinese medicine, which is a Daoist influence (I often think of Daoists as ancient Chinese scientists and engineers). Chinese medicine consider masturbation highly detrimental to one's health, and people should refrain from frequent sexual conduct to conserve more energy.
Whilst most modern medicine I encountered asserts masturbation is harmless, as the only vital material that is lost from the human body is protein and nutrients, which easily regenerates over time. Chinese medicine speculates beyond matter (i.e. semen), understands the world is composed of matter, energy, and information, and with each ejaculation a lot of energy is lost, which does most damage to the kidneys. For men aged between 30 ~ 40, this energy cycle takes about 2 weeks to replenish, and as we get older the cycle takes even longer. Chinese medicine highly recommend men to completely abstain after the age of 60, if you wish to enjoy longevity. In short, don't do it, it's good for your health.
Masturbation is also considered unwholesome sexual conduct. Confucianism teaches filial piety as the top priority of being a virtuous person. Our bodies are born from our mothers, through months of labor and hardship through birth, and then nourished and nurtured carefully by our parents. Therefore, Confucianism considers looking after our health as an essential component of filial piety. Not only is masturbation an unhealthy act, but it is also a shameful scene to behold if one were to be accidentally exposed to the public.
Based on the above, I do believe masturbation is a great hinderance towards samadhi.
Lastly, like any worldly attachments, I believe such an addiction can be resolved by practicing Buddhism diligently. Meditation does wonders. I have a Hare Krisna friend whom, after practicing meditation, naturally lost interest in meat and became a vegan with ease.
There are many ways and teachings in the Buddhist scriptures so simply find a way that is most suitable for one's circumstances. One of the most recommended approach is through 'Disgusting Thoughts' (asubhānupassin), by visualizing our fleshy bodies in separate parts in high details (the brain, stomach, skin, fecal matter, blood, pus etc) and see through what our bodies are really made of. The essence of desire is emptiness and relative. A mosquito would find another mosquito sexually attractive, but another creature, e.g. us human-beings, or a dog, would have no interest. In the eyes of the Devas, even the most attractive super models are merely foul hideous apes.
Please allow me to be frank (sorry everyone for the TMI) but, I too, had the same addiction for over 10 years. I was under the pretense it is harmless, but in retrospective, this behavior had adversed affected me psychologically. I was often shrouded with shame, I lack confidence, it warped my expectation with relationships and I could not experience satisfactory relationship.
I dropped the habit 'magically' after a few weeks practicing Buddhism. I have always admired and respected Buddhism, and when I first started to study it seriously, many of my bad habits just naturally faded. I deleted all adult material, eat healthy, went vegetarian, and now married and become a first time dad.
Sorry if the above sound a bit cliche. I'm still afflicted by lingering wandering thoughts, but at least I have not broken action precepts. I hope in time, and through diligent practice, all these anxiety will turn into Bodhi.